From 5efba3fda140f10bc9dfcedad61c4451d6a47799 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 1 Feb 2013 08:43:24 -0800 Subject: [PATCH] Improve handling of whitespace in the fonts collector When whitespace characters are missing in the font, print the names of the characters rather than seemingly printing nothing. Closes #1553. --- aegisub/src/font_file_lister.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index aacedc3bc..85afde84b 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -33,11 +33,34 @@ #include #include - +#include #include using namespace std::placeholders; +namespace { + wxString format_missing(wxString const& str) { + wxString printable; + wxString unprintable; + for (wxUniChar c : str) { + if (!u_isUWhiteSpace(c.GetValue())) + printable += c; + else { + unprintable += wxString::Format("\n - U+%04X ", c.GetValue()); + UErrorCode ec; + char buf[1024]; + auto len = u_charName(c.GetValue(), U_EXTENDED_CHAR_NAME, buf, sizeof buf, &ec); + if (len != 0 && U_SUCCESS(ec)) + unprintable += to_wx(buf); + if (c.GetValue() == 0xA0) + unprintable += " (\\h)"; + } + } + + return printable + unprintable; + } +} + FontCollector::FontCollector(FontCollectorStatusCallback status_callback, FontFileLister &lister) : status_callback(status_callback) , lister(lister) @@ -125,7 +148,7 @@ void FontCollector::ProcessChunk(std::pair const& style) { if (res.missing.size() > 50) status_callback(wxString::Format(_("'%s' is missing %d glyphs used.\n"), style.first.facename, (int)res.missing.size()), 2); else if (res.missing.size() > 0) - status_callback(wxString::Format(_("'%s' is missing the following glyphs used: %s\n"), style.first.facename, res.missing), 2); + status_callback(wxString::Format(_("'%s' is missing the following glyphs used: %s\n"), style.first.facename, format_missing(res.missing)), 2); PrintUsage(style.second); ++missing_glyphs; }