Merge pull request #17805 from hch12907/sdl-ttf

SDL: address comments on #17780
This commit is contained in:
Unknown W. Brackets 2023-07-30 07:10:59 -07:00 committed by GitHub
commit a28acf2662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 11 deletions

View File

@ -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<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(' ');

View File

@ -29,7 +29,7 @@ public:
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_;