Skip to content

Commit

Permalink
Only use JIS->UTF8 conversion with new overlay.
Browse files Browse the repository at this point in the history
Fix pixel font display.
  • Loading branch information
bearoso committed May 8, 2023
1 parent ff35034 commit 8719a47
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
29 changes: 28 additions & 1 deletion external/imgui/snes9x_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ static void ImGui_DrawTextOverlay(const char *text,
draw_list->AddText(nullptr, 0.0f, ImVec2(x + padding, y + padding), settings.text_color, text, nullptr, wrap_at);
}

static std::string sjis_to_utf8(std::string in)
{
std::string out;
for (const auto &i : in)
{
unsigned char c = i;
if (c > 160 && c < 192)
{
out += "\357\275";
out += c;
}
else if (c >= 192)
{
out += "\357\276";
c -= 0x40;
out += c;
}
else
out += c;
}

return out;
}

bool S9xImGuiDraw(int width, int height)
{
if (Memory.ROMFilename.empty())
Expand Down Expand Up @@ -223,13 +247,16 @@ bool S9xImGuiDraw(int width, int height)
}

if (!GFX.InfoString.empty())
ImGui_DrawTextOverlay(GFX.InfoString.c_str(),
{
auto utf8_message = sjis_to_utf8(GFX.InfoString);
ImGui_DrawTextOverlay(utf8_message.c_str(),
settings.spacing,
height - settings.spacing,
settings.spacing,
ImGui::DrawTextAlignment::BEGIN,
ImGui::DrawTextAlignment::END,
width - settings.spacing * 4);
}

ImGui::Render();

Expand Down
8 changes: 4 additions & 4 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel
int min_lines = 1;
std::string msg(string);
for (auto& c : msg)
if (c < 32)
if (c == '\n')
min_lines++;
if (min_lines > linesFromBottom)
linesFromBottom = min_lines;
Expand All @@ -1836,10 +1836,10 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel

for (int i = 0; i < len; i++)
{
int cindex = string[i] - 32;
int cindex = (uint8)string[i] - 32;
int char_width = font_width - (monospace ? 1 : (var8x10font_kern[cindex][0] + var8x10font_kern[cindex][1]));

if (dst_x + char_width > SNES_WIDTH || (uint8)string[i] < 32)
if (dst_x + char_width > SNES_WIDTH || string[i] == '\n')
{
if (!allowWrap)
break;
Expand All @@ -1852,7 +1852,7 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel
break;
}

if ((uint8)string[i] < 32)
if (string[i] == '\n')
continue;

VariableDisplayChar(dst_x, dst_y, string[i], monospace, overlap);
Expand Down
28 changes: 2 additions & 26 deletions memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3377,37 +3377,13 @@ const char * CMemory::PublishingCompany (void)
return (nintendo_licensees[CompanyId]);
}

static std::string sjis_to_utf8(std::string in)
{
std::string out;
for (const auto &i : in)
{
unsigned char c = i;
if (c > 160 && c < 192)
{
out += "\357\275";
out += c;
}
else if (c >= 192)
{
out += "\357\276";
c -= 0x40;
out += c;
}
else if (c >= 32)
out += c;
}

return out;
}

std::string CMemory::GetMultilineROMInfo()
{
bool8 isChecksumOK = (Memory.ROMChecksum + Memory.ROMComplementChecksum == 0xffff) &&
(Memory.ROMChecksum == Memory.CalculatedChecksum);
std::string utf8_romname = sjis_to_utf8(Memory.ROMName);
std::string utf8_romname = Memory.ROMName;
std::string tvstandard = Settings.PAL ? "PAL" : "NTSC";
std::string romid = sjis_to_utf8(Memory.ROMId);
std::string romid = Memory.ROMId;
std::string checksum = isChecksumOK ? "Checksum OK"
: Settings.IsPatched == 3 ? "UPS patched"
: Settings.IsPatched == 2 ? "BPS patched"
Expand Down

0 comments on commit 8719a47

Please sign in to comment.