diff --git a/src/Gui/DlgSettingsNavigation.cpp b/src/Gui/DlgSettingsNavigation.cpp index 7de4b2387f..635624d9ab 100644 --- a/src/Gui/DlgSettingsNavigation.cpp +++ b/src/Gui/DlgSettingsNavigation.cpp @@ -187,7 +187,7 @@ void DlgSettingsNavigation::loadSettings() // fill up font styles hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/NaviCube"); - std::string defaultSansserifFont = NaviCube::getDefaultSansserifFont().family().toStdString(); + std::string defaultSansserifFont = NaviCube::getDefaultSansserifFont().toStdString(); // we purposely allow all available fonts on the system #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -197,10 +197,6 @@ void DlgSettingsNavigation::loadSettings() #endif ui->naviCubeFontName->addItems(familyNames); - // if the parameter has not yet been set, do so immediately - // this assures it is set even if the user cancels the dialog - if (hGrp->GetASCII("FontString", "").empty()) - hGrp->SetASCII("FontString", defaultSansserifFont.c_str()); int indexFamilyNames = familyNames.indexOf( QString::fromStdString(hGrp->GetASCII("FontString", defaultSansserifFont.c_str()))); if (indexFamilyNames < 0) diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index 9c384540f9..7977f3bf00 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -292,22 +292,20 @@ void NaviCube::setFontSize(int size) m_NaviCubeImplementation->m_CubeTextSize = size; } -// sets a default sansserif font -// the Helvetica font is a good start for most OSes -QFont NaviCube::getDefaultSansserifFont() +QString NaviCube::getDefaultSansserifFont() { // Windows versions since 2017 have the 'Bahnschrift' font (a condensed // sans serif font, optimized for readability despite being condensed), // we first check for that. - QFont font(QString::fromLatin1("Bahnschrift")); - if (font.exactMatch()) - return font; + QFont font(QStringLiteral("Bahnschrift")); + if (!font.exactMatch()) + // On systems without 'Bahnschrift' we check for 'Helvetica' or its closest match + // as default sans serif font. (For Windows 7 this will e.g. result in 'Arial'.) + font = QFont(QStringLiteral("Helvetica")); - // On systems without 'Bahnschrift' we check for 'Helvetica' or its closest match - // as default sans serif font. (For Windows 7 this will e.g. result in 'Arial'.) - font = QString::fromLatin1("Helvetica"); font.setStyleHint(QFont::SansSerif); - return font; + // QFontInfo is required to get the actually matched font family + return QFontInfo(font).family(); } int NaviCube::getDefaultFontSize() @@ -406,7 +404,7 @@ void NaviCubeImplementation::OnChange(ParameterGrp::SubjectType& rCaller, } else if (strcmp(reason, "FontString") == 0) { m_CubeTextFont = (rGrp.GetASCII( - reason, NaviCube::getDefaultSansserifFont().family().toStdString().c_str())); + reason, NaviCube::getDefaultSansserifFont().toStdString().c_str())); } } diff --git a/src/Gui/NaviCube.h b/src/Gui/NaviCube.h index cdd196266a..6ed30c0c62 100644 --- a/src/Gui/NaviCube.h +++ b/src/Gui/NaviCube.h @@ -52,7 +52,7 @@ public: void setNaviStepByTurn(int steps); void setFont(std::string font); void setFontSize(int size); - static QFont getDefaultSansserifFont(); + static QString getDefaultSansserifFont(); int getDefaultFontSize(); static void setNaviCubeCommands(const std::vector& cmd); static void setNaviCubeLabels(const std::vector& labels); diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index f2ae6e1ffc..1b987df3e5 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -399,7 +399,7 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M } else if (strcmp(Reason, "FontString") == 0) { std::string font = rGrp.GetASCII( - "FontString", NaviCube::getDefaultSansserifFont().family().toStdString().c_str()); + "FontString", NaviCube::getDefaultSansserifFont().toStdString().c_str()); _viewer->getNavigationCube()->setFont(font); } else if (strcmp(Reason,"UseVBO") == 0) {