mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
Report salvaged and unreadable font descriptions after opening a project
Until now a font description that could not be parsed only produced console warnings most users never see, so nobody learned that their texts silently lost their formatting (see the reports in issue #553). Count in QETUtils::fontFromString() how many descriptions were salvaged from a foreign or corrupt format and how many stayed unreadable, and show a message box after opening a project when either happened: salvaged descriptions are rewritten in the stable format on the next save, unreadable ones fall back to the default font. Projects without font issues open exactly as before, and non-interactive opens only log the counters. Verified with a Qt 5.15 build on a project carrying 52 19-field and one 21-field description: the dialog reports 53 restored descriptions; the same file on a Qt 6.11 build (which parses those formats natively) shows no dialog. See issue #553.
This commit is contained in:
@@ -153,6 +153,12 @@ void QETUtils::pixelSizedFont(QFont &font)
|
||||
|
||||
namespace
|
||||
{
|
||||
/* Counters for fontFromString(), reset per project load so the editor
|
||||
* can report how many stored font descriptions needed salvaging or were
|
||||
* unreadable. Font parsing only happens on the main thread. */
|
||||
int salvaged_font_count = 0;
|
||||
int unreadable_font_count = 0;
|
||||
|
||||
/**
|
||||
* Legacy (Qt 5) weight <- OpenType weight, closest match,
|
||||
* same table Qt uses when parsing a 10/11 field string.
|
||||
@@ -235,6 +241,10 @@ QString QETUtils::fontToString(const QFont &font)
|
||||
*/
|
||||
bool QETUtils::fontFromString(QFont &font, const QString &description)
|
||||
{
|
||||
if (description.trimmed().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFont parsed(font);
|
||||
if (parsed.fromString(description)) {
|
||||
font = parsed;
|
||||
@@ -271,8 +281,10 @@ bool QETUtils::fontFromString(QFont &font, const QString &description)
|
||||
|
||||
if (parsed.fromString(legacy)) {
|
||||
font = parsed;
|
||||
++salvaged_font_count;
|
||||
return true;
|
||||
}
|
||||
++unreadable_font_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -284,7 +296,41 @@ bool QETUtils::fontFromString(QFont &font, const QString &description)
|
||||
if (count > 11
|
||||
&& parsed.fromString(QStringList(l.mid(0, 11)).join(comma))) {
|
||||
font = parsed;
|
||||
++salvaged_font_count;
|
||||
return true;
|
||||
}
|
||||
++unreadable_font_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETUtils::resetFontRestorationCounters
|
||||
* Reset the counters incremented by fontFromString(), to be called before
|
||||
* loading a project so the numbers reported afterwards are per-project.
|
||||
*/
|
||||
void QETUtils::resetFontRestorationCounters()
|
||||
{
|
||||
salvaged_font_count = 0;
|
||||
unreadable_font_count = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETUtils::salvagedFontCount
|
||||
* @return How many font descriptions fontFromString() restored from a
|
||||
* foreign or corrupt format since the counters were last reset. Such
|
||||
* descriptions are rewritten in the stable format on the next save.
|
||||
*/
|
||||
int QETUtils::salvagedFontCount()
|
||||
{
|
||||
return salvaged_font_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETUtils::unreadableFontCount
|
||||
* @return How many font descriptions fontFromString() could not restore at
|
||||
* all since the counters were last reset (the caller's default font applies).
|
||||
*/
|
||||
int QETUtils::unreadableFontCount()
|
||||
{
|
||||
return unreadable_font_count;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace QETUtils
|
||||
void pixelSizedFont (QFont &font);
|
||||
QString fontToString (const QFont &font);
|
||||
bool fontFromString (QFont &font, const QString &description);
|
||||
void resetFontRestorationCounters ();
|
||||
int salvagedFontCount ();
|
||||
int unreadableFontCount ();
|
||||
|
||||
bool sortBeginIntString(const QString &str_a, const QString &str_b);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user