Convert DrawString* functions to use std::string_view

This commit is contained in:
Henrik Rydgård
2024-05-24 14:05:23 +02:00
parent 804f31f424
commit ccbcf1369b
17 changed files with 72 additions and 65 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ void VFS::Clear() {
}
// TODO: Use Path more.
static bool IsLocalAbsolutePath(const char *path) {
static bool IsLocalAbsolutePath(std::string_view path) {
bool isUnixLocal = path[0] == '/';
#ifdef _WIN32
bool isWindowsLocal = (isalpha(path[0]) && path[1] == ':') || startsWith(path, "\\\\") || startsWith(path, "//");
+4 -4
View File
@@ -46,7 +46,7 @@ float TextDrawer::CalculateDPIScale() {
return scale;
}
void TextDrawer::DrawStringRect(DrawBuffer &target, const char *str, const Bounds &bounds, uint32_t color, int align) {
void TextDrawer::DrawStringRect(DrawBuffer &target, std::string_view str, const Bounds &bounds, uint32_t color, int align) {
float x = bounds.x;
float y = bounds.y;
if (align & ALIGN_HCENTER) {
@@ -60,7 +60,7 @@ void TextDrawer::DrawStringRect(DrawBuffer &target, const char *str, const Bound
y = bounds.y2();
}
std::string toDraw = str;
std::string toDraw(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
@@ -70,8 +70,8 @@ void TextDrawer::DrawStringRect(DrawBuffer &target, const char *str, const Bound
DrawString(target, toDraw.c_str(), x, y, color, align);
}
void TextDrawer::DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, const Bounds &bounds, int align) {
std::string toDraw = str;
void TextDrawer::DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, const Bounds &bounds, int align) {
std::string toDraw(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
+4 -4
View File
@@ -46,10 +46,10 @@ public:
void SetFontScale(float xscale, float yscale);
virtual void MeasureString(std::string_view str, float *w, float *h) = 0;
virtual void MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) = 0;
virtual void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) = 0;
void DrawStringRect(DrawBuffer &target, const char *str, const Bounds &bounds, uint32_t color, int align);
virtual void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align = ALIGN_TOPLEFT) = 0;
void DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, const Bounds &bounds, int align);
virtual void DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) = 0;
void DrawStringRect(DrawBuffer &target, std::string_view str, const Bounds &bounds, uint32_t color, int align);
virtual void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) = 0;
void DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, const Bounds &bounds, int align);
// Use for housekeeping like throwing out old strings.
virtual void OncePerFrame() = 0;
+6 -6
View File
@@ -174,8 +174,8 @@ void TextDrawerAndroid::MeasureStringRect(std::string_view str, const Bounds &bo
*h = total_h * fontScaleY_ * dpiScale_;
}
void TextDrawerAndroid::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align) {
if (!strlen(str)) {
void TextDrawerAndroid::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align) {
if (str.empty()) {
bitmapData.clear();
return;
}
@@ -189,7 +189,7 @@ void TextDrawerAndroid::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextS
}
auto env = getEnv();
jstring jstr = env->NewStringUTF(str);
jstring jstr = env->NewStringUTF(std::string(str).c_str());
uint32_t textSize = env->CallStaticIntMethod(cls_textRenderer, method_measureText, jstr, size);
int imageWidth = (short)(textSize >> 16);
int imageHeight = (short)(textSize & 0xFFFF);
@@ -246,9 +246,9 @@ void TextDrawerAndroid::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextS
env->DeleteLocalRef(imageData);
}
void TextDrawerAndroid::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) {
void TextDrawerAndroid::DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align) {
using namespace Draw;
if (!str)
if (str.empty())
return;
std::string text(NormalizeString(std::string(str)));
@@ -275,7 +275,7 @@ void TextDrawerAndroid::DrawString(DrawBuffer &target, const char *str, float x,
TextureDesc desc{};
std::vector<uint8_t> bitmapData;
DrawStringBitmap(bitmapData, *entry, texFormat, text.c_str(), align);
DrawStringBitmap(bitmapData, *entry, texFormat, text, align);
desc.initData.push_back(&bitmapData[0]);
desc.type = TextureType::LINEAR2D;
+2 -2
View File
@@ -23,8 +23,8 @@ public:
void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once.
void MeasureString(std::string_view str, float *w, float *h) override;
void MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) override;
// Use for housekeeping like throwing out old strings.
void OncePerFrame() override;
+10 -9
View File
@@ -51,7 +51,7 @@ void TextDrawerQt::SetFont(uint32_t fontHandle) {
}
}
void TextDrawerQt::MeasureString(std::string_view str, size_t len, float *w, float *h) {
void TextDrawerQt::MeasureString(std::string_view str, float *w, float *h) {
CacheKey key{ std::string(str), fontHash_ };
TextMeasureEntry *entry;
@@ -74,8 +74,8 @@ void TextDrawerQt::MeasureString(std::string_view str, size_t len, float *w, flo
*h = entry->height * fontScaleY_ * dpiScale_;
}
void TextDrawerQt::MeasureStringRect(const char *str, size_t len, const Bounds &bounds, float *w, float *h, int align) {
std::string toMeasure = std::string(str, len);
void TextDrawerQt::MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align) {
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
@@ -89,15 +89,15 @@ void TextDrawerQt::MeasureStringRect(const char *str, size_t len, const Bounds &
*h = (float)size.height() * fontScaleY_ * dpiScale_;
}
void TextDrawerQt::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align) {
if (!strlen(str)) {
void TextDrawerQt::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align) {
if (str.empty()) {
bitmapData.clear();
return;
}
QFont *font = fontMap_.find(fontHash_)->second;
QFontMetrics fm(*font);
QSize size = fm.size(0, QString::fromUtf8(str));
QSize size = fm.size(0, QString::fromUtf8(str.data(), str.length()));
QImage image((size.width() + 3) & ~3, (size.height() + 3) & ~3, QImage::Format_ARGB32_Premultiplied);
if (image.isNull()) {
bitmapData.clear();
@@ -110,7 +110,7 @@ void TextDrawerQt::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextString
painter.setFont(*font);
painter.setPen(0xFFFFFFFF);
// TODO: Involve ALIGN_HCENTER (bounds etc.)
painter.drawText(image.rect(), Qt::AlignTop | Qt::AlignLeft, QString::fromUtf8(str).replace("&&", "&"));
painter.drawText(image.rect(), Qt::AlignTop | Qt::AlignLeft, QString::fromUtf8(str.data(), str.length()).replace("&&", "&"));
painter.end();
entry.texture = nullptr;
@@ -138,10 +138,11 @@ void TextDrawerQt::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextString
}
}
void TextDrawerQt::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) {
void TextDrawerQt::DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align) {
using namespace Draw;
if (!strlen(str))
if (str.empty()) {
return;
}
CacheKey key{ std::string(str), fontHash_ };
target.Flush(true);
+4 -4
View File
@@ -16,10 +16,10 @@ public:
uint32_t SetFont(const char *fontName, int size, int flags) override;
void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once.
void MeasureString(std::string_view str, size_t len, float *w, float *h) override;
void MeasureStringRect(std::string_view str, size_t len, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align = ALIGN_TOPLEFT) override;
void MeasureString(std::string_view str, float *w, float *h) override;
void MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) override;
// Use for housekeeping like throwing out old strings.
void OncePerFrame() override;
+6 -6
View File
@@ -277,7 +277,7 @@ void TextDrawerSDL::SetFont(uint32_t fontHandle) {
}
}
void TextDrawerSDL::MeasureString(std::string_view str, size_t len, float *w, float *h) {
void TextDrawerSDL::MeasureString(std::string_view str, float *w, float *h) {
CacheKey key{ std::string(str), fontHash_ };
TextMeasureEntry *entry;
@@ -312,7 +312,7 @@ void TextDrawerSDL::MeasureString(std::string_view str, size_t len, float *w, fl
*h = entry->height * fontScaleY_ * dpiScale_;
}
void TextDrawerSDL::MeasureStringRect(std::string_view str, size_t len, const Bounds &bounds, float *w, float *h, int align) {
void TextDrawerSDL::MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align) {
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
@@ -364,9 +364,9 @@ void TextDrawerSDL::MeasureStringRect(std::string_view str, size_t len, const Bo
*h = total_h * fontScaleY_ * dpiScale_;
}
void TextDrawerSDL::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) {
void TextDrawerSDL::DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align) {
using namespace Draw;
if (!strlen(str))
if (str.empty())
return;
CacheKey key{ std::string(str), fontHash_ };
@@ -416,8 +416,8 @@ void TextDrawerSDL::DrawString(DrawBuffer &target, const char *str, float x, flo
}
}
void TextDrawerSDL::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align) {
if (!strlen(str)) {
void TextDrawerSDL::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align) {
if (str.empty()) {
bitmapData.clear();
return;
}
+2 -2
View File
@@ -21,8 +21,8 @@ public:
void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once.
void MeasureString(std::string_view str, float *w, float *h) override;
void MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) override;
// Use for housekeeping like throwing out old strings.
void OncePerFrame() override;
+10 -9
View File
@@ -198,8 +198,8 @@ void TextDrawerUWP::SetFont(uint32_t fontHandle) {
}
}
void TextDrawerUWP::MeasureString(std::string_view str, size_t len, float *w, float *h) {
CacheKey key{ std::string(str, len), fontHash_ };
void TextDrawerUWP::MeasureString(std::string_view str, float *w, float *h) {
CacheKey key{ std::string(str), fontHash_ };
TextMeasureEntry *entry;
auto iter = sizeCache_.find(key);
@@ -213,7 +213,7 @@ void TextDrawerUWP::MeasureString(std::string_view str, size_t len, float *w, fl
}
if (!format) return;
std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str, len), "\n", "\r\n"), "&&", "&"));
std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str), "\n", "\r\n"), "&&", "&"));
format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
@@ -242,7 +242,7 @@ void TextDrawerUWP::MeasureString(std::string_view str, size_t len, float *w, fl
*h = entry->height * fontScaleY_ * dpiScale_;
}
void TextDrawerUWP::MeasureStringRect(std::string_view str, size_t len, const Bounds &bounds, float *w, float *h, int align) {
void TextDrawerUWP::MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align) {
IDWriteTextFormat *format = nullptr;
auto iter = fontMap_.find(fontHash_);
if (iter != fontMap_.end()) {
@@ -254,7 +254,7 @@ void TextDrawerUWP::MeasureStringRect(std::string_view str, size_t len, const Bo
return;
}
std::string toMeasure = std::string(str, len);
std::string toMeasure = std::string(str);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0;
@@ -312,8 +312,8 @@ void TextDrawerUWP::MeasureStringRect(std::string_view str, size_t len, const Bo
*h = total_h * fontScaleY_ * dpiScale_;
}
void TextDrawerUWP::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align) {
if (!strlen(str)) {
void TextDrawerUWP::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align) {
if (!str.empty()) {
bitmapData.clear();
return;
}
@@ -439,10 +439,11 @@ void TextDrawerUWP::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStrin
ctx_->mirror_bmp->Unmap();
}
void TextDrawerUWP::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) {
void TextDrawerUWP::DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align) {
using namespace Draw;
if (!strlen(str))
if (str.empty()) {
return;
}
CacheKey key{ std::string(str), fontHash_ };
target.Flush(true);
+4 -4
View File
@@ -21,10 +21,10 @@ public:
uint32_t SetFont(const char *fontName, int size, int flags) override;
void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once.
void MeasureString(std::string_view str, size_t len, float *w, float *h) override;
void MeasureStringRect(std::string_view str, size_t len, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align = ALIGN_TOPLEFT) override;
void MeasureString(std::string_view str, float *w, float *h) override;
void MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) override;
// Use for housekeeping like throwing out old strings.
void OncePerFrame() override;
+5 -4
View File
@@ -211,8 +211,8 @@ void TextDrawerWin32::MeasureStringRect(std::string_view str, const Bounds &boun
*h = total_h * fontScaleY_ * dpiScale_;
}
void TextDrawerWin32::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align) {
if (!strlen(str)) {
void TextDrawerWin32::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align) {
if (str.empty()) {
bitmapData.clear();
return;
}
@@ -304,10 +304,11 @@ void TextDrawerWin32::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStr
}
}
void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) {
void TextDrawerWin32::DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align) {
using namespace Draw;
if (!strlen(str))
if (str.empty()) {
return;
}
CacheKey key{ std::string(str), fontHash_ };
target.Flush(true);
+2 -2
View File
@@ -23,8 +23,8 @@ public:
void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once.
void MeasureString(std::string_view str, float *w, float *h) override;
void MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, const char *str, int align = ALIGN_TOPLEFT) override;
void DrawString(DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override;
void DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) override;
// Use for housekeeping like throwing out old strings.
void OncePerFrame() override;
+4
View File
@@ -102,6 +102,10 @@ inline size_t truncate_cpy(char(&out)[Count], const char *src) {
return truncate_cpy(out, Count, src);
}
size_t truncate_cpy(char *dest, size_t destSize, std::string_view src);
template<size_t Count>
inline size_t truncate_cpy(char(&out)[Count], std::string_view src) {
return truncate_cpy(out, Count, src);
}
const char* safe_string(const char* s);
+3 -3
View File
@@ -248,9 +248,9 @@ std::string PopupSliderChoice::ValueText() const {
char temp[256];
temp[0] = '\0';
if (zeroLabel_.size() && *value_ == 0) {
truncate_cpy(temp, zeroLabel_.c_str());
truncate_cpy(temp, zeroLabel_);
} else if (negativeLabel_.size() && *value_ < 0) {
truncate_cpy(temp, negativeLabel_.c_str());
truncate_cpy(temp, negativeLabel_);
} else {
// Would normally be dangerous to have user-controlled format strings!
// However, let's check that there's only one % sign, and that it's not followed by an S.
@@ -290,7 +290,7 @@ std::string PopupSliderChoiceFloat::ValueText() const {
char temp[256];
temp[0] = '\0';
if (zeroLabel_.size() && *value_ == 0.0f) {
truncate_cpy(temp, zeroLabel_.c_str());
truncate_cpy(temp, zeroLabel_);
} else if (IsValidNumberFormatString(fmt_)) {
snprintf(temp, sizeof(temp), fmt_.c_str(), *value_);
} else {
+4 -4
View File
@@ -785,7 +785,7 @@ void PPGeMeasureText(float *w, float *h, std::string_view text, float scale, int
if (WrapType & PPGE_LINE_USE_ELLIPSIS)
dtalign |= FLAG_ELLIPSIZE_TEXT;
Bounds b(0, 0, wrapWidth <= 0 ? 480.0f : wrapWidth, 272.0f);
textDrawer->MeasureStringRect(s2.c_str(), s2.size(), b, &mw, &mh, dtalign);
textDrawer->MeasureStringRect(s2, b, &mw, &mh, dtalign);
if (w)
*w = mw;
@@ -1119,15 +1119,15 @@ void PPGeDrawTextWrapped(std::string_view text, float x, float y, float wrapWidt
Bounds b(0, 0, wrapWidth <= 0 ? 480.0f - x : wrapWidth, wrapHeight);
int tdalign = 0;
textDrawer->SetFontScale(style.scale, style.scale);
textDrawer->MeasureStringRect(s2.c_str(), s2.size(), b, &actualWidth, &actualHeight, tdalign | FLAG_WRAP_TEXT);
textDrawer->MeasureStringRect(s2, b, &actualWidth, &actualHeight, tdalign | FLAG_WRAP_TEXT);
// Check if we need to scale the text down to fit better.
PPGeStyle adjustedStyle = style;
if (wrapHeight != 0.0f && actualHeight > wrapHeight) {
// Cheap way to get the line height.
float oneLine, twoLines;
textDrawer->MeasureString("|", 1, &actualWidth, &oneLine);
textDrawer->MeasureStringRect("|\n|", 3, Bounds(0, 0, 480, 272), &actualWidth, &twoLines);
textDrawer->MeasureString("|", &actualWidth, &oneLine);
textDrawer->MeasureStringRect("|\n|", Bounds(0, 0, 480, 272), &actualWidth, &twoLines);
float lineHeight = twoLines - oneLine;
if (actualHeight > wrapHeight * maxScaleDown) {
+1 -1
View File
@@ -560,7 +560,7 @@ static void RenderGameAchievementSummary(UIContext &dc, const Bounds &bounds, fl
std::string description = Achievements::GetGameAchievementSummary();
dc.SetFontScale(0.66f, 0.66f);
dc.DrawTextRect(description.c_str(), bounds.Inset(iconSpace + 5.0f, 38.0f, 5.0f, 5.0f), fgColor, ALIGN_TOPLEFT);
dc.DrawTextRect(description, bounds.Inset(iconSpace + 5.0f, 38.0f, 5.0f, 5.0f), fgColor, ALIGN_TOPLEFT);
dc.SetFontScale(1.0f, 1.0f);
dc.Flush();