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.
This commit is contained in:
Thomas Goyne 2013-02-01 08:43:24 -08:00
parent 2a5134a5ca
commit 5efba3fda1

View file

@ -33,11 +33,34 @@
#include <algorithm> #include <algorithm>
#include <tuple> #include <tuple>
#include <unicode/uchar.h>
#include <wx/intl.h> #include <wx/intl.h>
using namespace std::placeholders; 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) FontCollector::FontCollector(FontCollectorStatusCallback status_callback, FontFileLister &lister)
: status_callback(status_callback) : status_callback(status_callback)
, lister(lister) , lister(lister)
@ -125,7 +148,7 @@ void FontCollector::ProcessChunk(std::pair<StyleInfo, UsageData> const& style) {
if (res.missing.size() > 50) if (res.missing.size() > 50)
status_callback(wxString::Format(_("'%s' is missing %d glyphs used.\n"), style.first.facename, (int)res.missing.size()), 2); 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) 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); PrintUsage(style.second);
++missing_glyphs; ++missing_glyphs;
} }