Salvage font descriptions written by Qt 6.11+ when parsing fails

QFont::fromString() of Qt 5.x and Qt <= 6.10 rejects the >= 19 field
descriptions QFont::toString() emits since Qt 6.11, silently leaving a
broken font at every read site. Add QETUtils::fontFromString(): try the
native parser first, and on failure re-compose the legacy 10/11 field
form from the known Qt 6.11 field layout (OpenType weight mapped back
to the legacy scale) so no font information stored in existing files is
lost. Also salvage the 21 field double-serialized descriptions left
behind by some historical builds (a complete legacy description
embedded as the family name of a second one) by taking the embedded
leading description, matching what the lenient parser of Qt 6.11+
resolves them to. All font read sites now go through the helper; on
failure the default font of the caller is left untouched instead of a
cleared family.

Verified end to end on a Qt 5.15 build: a project whose 53 font
attributes were rewritten into the 19 field Qt 6.11 format loads and
autosaves byte-identical to the original legacy file (family, sizes,
bold/italic/underline, style name all preserved), and a mixed file
containing the exact 21 field string from the issue comes back
normalized as "Caladea,9,-1,5,75,1,0,0,0,0,Bold Italic".

See issue #553.
This commit is contained in:
Dieter Mayer
2026-07-31 07:58:54 +02:00
parent 5da1fe5fc8
commit 68ffacc9e6
13 changed files with 118 additions and 33 deletions
+3 -2
View File
@@ -26,6 +26,7 @@
#include "projectview.h"
#include "qetdiagrameditor.h"
#include "qeticons.h"
#include "utils/qetutils.h"
#include "qetmessagebox.h"
#include "qetproject.h"
#include "qtextorientationspinboxwidget.h"
@@ -1425,7 +1426,7 @@ QFont QETApp::diagramTextsItemFont(qreal size)
//Font to use
QFont font_ = diagramTextsItemFont();
if (settings.contains("diagrameditor/dynamic_text_font")) {
font_.fromString(settings.value(
QETUtils::fontFromString(font_, settings.value(
"diagrameditor/dynamic_text_font"
).toString());
}
@@ -1449,7 +1450,7 @@ QFont QETApp::indiTextsItemFont(qreal size)
//Font to use
QFont font_ = diagramTextsItemFont();
if (settings.contains("diagrameditor/independent_text_font")) {
font_.fromString(settings.value(
QETUtils::fontFromString(font_, settings.value(
"diagrameditor/independent_text_font"
).toString());
}