Skip to content

Commit 1935bba

Browse files
authored
Merge pull request #19482 from hrydgard/ppge-double-ampersand
Remove double ampersands from PPGe-drawn text (in-game UI)
2 parents f5c42d1 + 5a6c767 commit 1935bba

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

Core/MIPS/MIPSTracer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void MIPSTracer::prepare_block(const MIPSComp::IRBlock* block, MIPSComp::IRBlock
9494
trace_info.push_back({ virt_addr, storage_index });
9595

9696

97-
u32 index = trace_info.size() - 1;
97+
u32 index = (u32)(trace_info.size() - 1);
9898
auto ir_ptr = (IRInst*)blocks.GetBlockInstructionPtr(*block);
9999
ir_ptr[1].constant = index;
100100
}

Core/Util/PPGeDraw.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -780,15 +780,13 @@ void PPGeMeasureText(float *w, float *h, std::string_view text, float scale, int
780780
std::string s = PPGeSanitizeText(text);
781781

782782
if (HasTextDrawer()) {
783-
std::string s2 = ReplaceAll(s, "&", "&&");
784-
785783
float mw, mh;
786784
textDrawer->SetFontScale(scale, scale);
787785
int dtalign = (WrapType & PPGE_LINE_WRAP_WORD) ? FLAG_WRAP_TEXT : 0;
788786
if (WrapType & PPGE_LINE_USE_ELLIPSIS)
789787
dtalign |= FLAG_ELLIPSIZE_TEXT;
790788
Bounds b(0, 0, wrapWidth <= 0 ? 480.0f : wrapWidth, 272.0f);
791-
textDrawer->MeasureStringRect(s2, b, &mw, &mh, dtalign);
789+
textDrawer->MeasureStringRect(s, b, &mw, &mh, dtalign);
792790

793791
if (w)
794792
*w = mw;
@@ -898,14 +896,14 @@ inline int GetPow2(int x) {
898896
return ret;
899897
}
900898

901-
static PPGeTextDrawerImage PPGeGetTextImage(const char *text, const PPGeStyle &style, float maxWidth, bool wrap) {
899+
static PPGeTextDrawerImage PPGeGetTextImage(std::string_view text, const PPGeStyle &style, float maxWidth, bool wrap) {
902900
int tdalign = 0;
903901
tdalign |= FLAG_ELLIPSIZE_TEXT;
904902
if (wrap) {
905903
tdalign |= FLAG_WRAP_TEXT;
906904
}
907905

908-
PPGeTextDrawerCacheKey key{ text, tdalign, maxWidth / style.scale };
906+
PPGeTextDrawerCacheKey key{ std::string(text), tdalign, maxWidth / style.scale };
909907
PPGeTextDrawerImage im{};
910908

911909
auto cacheItem = textDrawerImages.find(key);
@@ -1065,7 +1063,7 @@ void PPGeDrawText(std::string_view text, float x, float y, const PPGeStyle &styl
10651063
}
10661064

10671065
if (HasTextDrawer()) {
1068-
PPGeTextDrawerImage im = PPGeGetTextImage(ReplaceAll(str, "&", "&&").c_str(), style, 480.0f - x, false);
1066+
PPGeTextDrawerImage im = PPGeGetTextImage(str, style, 480.0f - x, false);
10691067
if (im.ptr) {
10701068
PPGeDrawTextImage(im, x, y, style);
10711069
return;
@@ -1116,13 +1114,11 @@ void PPGeDrawTextWrapped(std::string_view text, float x, float y, float wrapWidt
11161114
float maxScaleDown = zoom == 1 ? 1.3f : 2.0f;
11171115

11181116
if (HasTextDrawer()) {
1119-
std::string s2 = ReplaceAll(s, "&", "&&");
1120-
11211117
float actualWidth, actualHeight;
11221118
Bounds b(0, 0, wrapWidth <= 0 ? 480.0f - x : wrapWidth, wrapHeight);
11231119
int tdalign = 0;
11241120
textDrawer->SetFontScale(style.scale, style.scale);
1125-
textDrawer->MeasureStringRect(s2, b, &actualWidth, &actualHeight, tdalign | FLAG_WRAP_TEXT);
1121+
textDrawer->MeasureStringRect(s, b, &actualWidth, &actualHeight, tdalign | FLAG_WRAP_TEXT);
11261122

11271123
// Check if we need to scale the text down to fit better.
11281124
PPGeStyle adjustedStyle = style;
@@ -1138,14 +1134,14 @@ void PPGeDrawTextWrapped(std::string_view text, float x, float y, float wrapWidt
11381134
actualHeight = (maxLines + 1) * lineHeight;
11391135
// Add an ellipsis if it's just too long to be readable.
11401136
// On a PSP, it does this without scaling it down.
1141-
s2 = StripTrailingWhite(CropLinesToCount(s2, (int)maxLines));
1142-
s2.append("\n...");
1137+
s = StripTrailingWhite(CropLinesToCount(s, (int)maxLines));
1138+
s.append("\n...");
11431139
}
11441140

11451141
adjustedStyle.scale *= wrapHeight / actualHeight;
11461142
}
11471143

1148-
PPGeTextDrawerImage im = PPGeGetTextImage(s2.c_str(), adjustedStyle, wrapWidth <= 0 ? 480.0f - x : wrapWidth, true);
1144+
PPGeTextDrawerImage im = PPGeGetTextImage(s, adjustedStyle, wrapWidth <= 0 ? 480.0f - x : wrapWidth, true);
11491145
if (im.ptr) {
11501146
PPGeDrawTextImage(im, x, y, adjustedStyle);
11511147
return;

0 commit comments

Comments
 (0)