mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Merge pull request #20182 from hrydgard/more-minor-fixes
Fix another linebreak issue in savedata dialog
This commit is contained in:
commit
81a067ab15
7 changed files with 37 additions and 21 deletions
|
@ -151,14 +151,14 @@ void TextDrawer::MeasureString(std::string_view str, float *w, float *h) {
|
|||
}
|
||||
|
||||
void TextDrawer::MeasureStringRect(std::string_view str, const Bounds &bounds, float *w, float *h, int align) {
|
||||
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
|
||||
const int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
|
||||
|
||||
float plainW, plainH;
|
||||
MeasureString(str, &plainW, &plainH);
|
||||
|
||||
if (wrap && plainW > bounds.w) {
|
||||
std::string toMeasure = std::string(str);
|
||||
WrapString(toMeasure, toMeasure.c_str(), bounds.w, wrap);
|
||||
WrapString(toMeasure, toMeasure, bounds.w, wrap);
|
||||
MeasureString(toMeasure, w, h);
|
||||
} else {
|
||||
*w = plainW;
|
||||
|
@ -189,7 +189,7 @@ void TextDrawer::DrawStringRect(DrawBuffer &target, std::string_view str, const
|
|||
WrapString(toDraw, str, bounds.w, wrap);
|
||||
}
|
||||
|
||||
DrawString(target, toDraw.c_str(), x, y, color, align);
|
||||
DrawString(target, toDraw, x, y, color, align);
|
||||
}
|
||||
|
||||
bool TextDrawer::DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, const Bounds &bounds, int align, bool fullColor) {
|
||||
|
@ -198,7 +198,7 @@ bool TextDrawer::DrawStringBitmapRect(std::vector<uint8_t> &bitmapData, TextStri
|
|||
if (wrap) {
|
||||
WrapString(toDraw, str, bounds.w, wrap);
|
||||
}
|
||||
return DrawStringBitmap(bitmapData, entry, texFormat, toDraw.c_str(), align, fullColor);
|
||||
return DrawStringBitmap(bitmapData, entry, texFormat, toDraw, align, fullColor);
|
||||
}
|
||||
|
||||
void TextDrawer::ClearCache() {
|
||||
|
|
|
@ -126,6 +126,12 @@ void TextDrawerWin32::MeasureStringInternal(std::string_view str, float *w, floa
|
|||
SelectObject(ctx_->hDC, iter->second->hFont);
|
||||
}
|
||||
|
||||
#if 0 && defined(_DEBUG)
|
||||
if (str.find('\r') != std::string_view::npos) {
|
||||
_dbg_assert_msg_(false, "carriage return found in string to measure");
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string toMeasure(str);
|
||||
|
||||
std::vector<std::string_view> lines;
|
||||
|
@ -135,8 +141,11 @@ void TextDrawerWin32::MeasureStringInternal(std::string_view str, float *w, floa
|
|||
for (auto &line : lines) {
|
||||
SIZE size;
|
||||
std::wstring wstr = ConvertUTF8ToWString(line);
|
||||
if (wstr.empty() && lines.size() > 1) {
|
||||
// Measure empty lines as if it was a space.
|
||||
wstr = L" ";
|
||||
}
|
||||
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);
|
||||
|
||||
if (size.cx > extW)
|
||||
extW = size.cx;
|
||||
extH += size.cy;
|
||||
|
|
|
@ -137,10 +137,16 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction
|
|||
lastWasLineBreak = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case StringRestriction::ConvertToUnixEndings: // Strips off carriage returns, keeps line feeds.
|
||||
if (c != '\r') {
|
||||
sanitized.push_back(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (minLength >= 0) {
|
||||
if (minLength > 0) {
|
||||
if ((int)sanitized.size() < minLength) {
|
||||
// Just reject it by returning an empty string, as we can't really
|
||||
// conjure up new characters here.
|
||||
|
|
|
@ -80,9 +80,10 @@ enum class StringRestriction {
|
|||
None,
|
||||
AlphaNumDashUnderscore, // Used for infrastructure usernames
|
||||
NoLineBreaksOrSpecials, // Used for savedata UI. Removes line breaks, backslashes and similar.
|
||||
ConvertToUnixEndings,
|
||||
};
|
||||
|
||||
std::string SanitizeString(std::string_view username, StringRestriction restriction, int minLength, int maxLength);
|
||||
std::string SanitizeString(std::string_view username, StringRestriction restriction, int minLength = 0, int maxLength = -1);
|
||||
|
||||
void DataToHexString(const uint8_t *data, size_t size, std::string *output, bool lineBreaks = true);
|
||||
void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output);
|
||||
|
|
|
@ -75,7 +75,7 @@ SavedataView::SavedataView(UIContext &dc, const Path &savePath, IdentifiedFileTy
|
|||
mTime_->SetTextColor(textStyle.fgColor);
|
||||
toprow->Add(topright);
|
||||
Add(new Spacer(3.0));
|
||||
detail_ = Add(new TextView(ReplaceAll(savedataDetail, "\r", ""), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(Margins(10, 0))));
|
||||
detail_ = Add(new TextView(SanitizeString(savedataDetail, StringRestriction::ConvertToUnixEndings), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(Margins(10, 0))));
|
||||
detail_->SetTextColor(textStyle.fgColor);
|
||||
Add(new Spacer(3.0));
|
||||
} else {
|
||||
|
@ -92,15 +92,16 @@ SavedataView::SavedataView(UIContext &dc, const Path &savePath, IdentifiedFileTy
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: This runs every frame, which is a bit silly.
|
||||
void SavedataView::UpdateGame(GameInfo *ginfo) {
|
||||
if (!ginfo->Ready(GameInfoFlags::PARAM_SFO | GameInfoFlags::SIZE)) {
|
||||
return;
|
||||
}
|
||||
if (savedataTitle_) {
|
||||
savedataTitle_->SetText(ginfo->GetParamSFO().GetValueString("SAVEDATA_TITLE"));
|
||||
savedataTitle_->SetText(SanitizeString(ginfo->GetParamSFO().GetValueString("SAVEDATA_TITLE"), StringRestriction::NoLineBreaksOrSpecials));
|
||||
}
|
||||
if (detail_) {
|
||||
detail_->SetText(ginfo->GetParamSFO().GetValueString("SAVEDATA_DETAIL"));
|
||||
detail_->SetText(SanitizeString(ginfo->GetParamSFO().GetValueString("SAVEDATA_DETAIL"), StringRestriction::ConvertToUnixEndings));
|
||||
}
|
||||
if (fileSize_) {
|
||||
fileSize_->SetText(NiceSizeFormat(ginfo->gameSizeOnDisk));
|
||||
|
|
|
@ -37,16 +37,11 @@ public class TextRenderer {
|
|||
}
|
||||
|
||||
private static Point measureLine(String string, double textSize) {
|
||||
int w;
|
||||
if (!string.isEmpty()) {
|
||||
textPaint.setTextSize((float) textSize);
|
||||
w = (int) textPaint.measureText(string);
|
||||
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures
|
||||
// which OpenGL does not like - each line must be 4-byte aligned
|
||||
w = (w + 5) & ~1;
|
||||
} else {
|
||||
w = 1;
|
||||
}
|
||||
textPaint.setTextSize((float) textSize);
|
||||
int w = (int) textPaint.measureText(string);
|
||||
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures
|
||||
// which OpenGL does not like - each line must be 4-byte aligned
|
||||
w = (w + 5) & ~1;
|
||||
int h = (int) (textPaint.descent() - textPaint.ascent() + 2.0f);
|
||||
Point p = new Point();
|
||||
p.x = w;
|
||||
|
@ -55,7 +50,7 @@ public class TextRenderer {
|
|||
}
|
||||
|
||||
private static Point measure(String string, double textSize) {
|
||||
String [] lines = string.replaceAll("\\r", "").split("\n");
|
||||
String [] lines = string.replaceAll("\r", "").split("\n");
|
||||
Point total = new Point();
|
||||
total.x = 0;
|
||||
for (String line : lines) {
|
||||
|
|
|
@ -1415,6 +1415,10 @@ UCUS98646 = true
|
|||
ULUS10213 = true
|
||||
ULES00483 = true
|
||||
|
||||
# G.I Joe The Rise of Cobra hang workaround (#12374)
|
||||
ULUS10435 = true
|
||||
ULES01277 = true
|
||||
|
||||
[ForceLowerResolutionForEffectsOn]
|
||||
# The water effect of DiRT 2 and Outrun doesn't work in higher resolutions.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue