mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-25 14:24:40 +00:00
dd53928de8
* Fixes #284880 * Also discussed on https://discourse.nixos.org/t/freecad-failed-to-compute-left-right-minimum-bearings-for-cursor-pcf/35266 Symptom is that failure to load a fixed font is followed by a flood of 'Failed to compute left/right minimum bearings for "cursor.pcf"' messages that can freeze up the machine. Isssue FreeCAD issue tracker https://github.com/FreeCAD/FreeCAD/issues/10514 Is not yet fixed, but with a working solution, which has not made it into the repo yet: https://github.com/FreeCAD/FreeCAD/issues/10514#issuecomment-1849176386 The hotfix from that comment is added here slightly adated as freecad-font-10514.patch
62 lines
2.1 KiB
Diff
62 lines
2.1 KiB
Diff
diff --git a/src/Gui/PreferencePages/DlgSettingsEditor.cpp b/src/Gui/PreferencePages/DlgSettingsEditor.cpp
|
|
index 5f92058c18..b00104497b 100644
|
|
--- a/src/Gui/PreferencePages/DlgSettingsEditor.cpp
|
|
+++ b/src/Gui/PreferencePages/DlgSettingsEditor.cpp
|
|
@@ -56,27 +56,34 @@ namespace
|
|
*
|
|
* Based on
|
|
* https://stackoverflow.com/questions/18896933/qt-qfont-selection-of-a-monospace-font-doesnt-work
|
|
+ * Local fix to based on comment in
|
|
+ * https://github.com/FreeCAD/FreeCAD/issues/10514#issuecomment-1849176386
|
|
*/
|
|
+bool hasFixedPitch(const QFont& font)
|
|
+{
|
|
+ return QFontInfo(font).fixedPitch();
|
|
+}
|
|
+
|
|
QFont getMonospaceFont()
|
|
{
|
|
- QFont font(QString::fromLatin1("monospace"));
|
|
- if (font.fixedPitch()) {
|
|
- return font;
|
|
- }
|
|
- font.setStyleHint(QFont::Monospace);
|
|
- if (font.fixedPitch()) {
|
|
- return font;
|
|
+ if (QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); hasFixedPitch(font)) {
|
|
+ return font; // should typically work.
|
|
}
|
|
- font.setStyleHint(QFont::TypeWriter);
|
|
- if (font.fixedPitch()) {
|
|
+
|
|
+ QFont font; // default QApplication font
|
|
+ font.setStyleHint(QFont::Courier); // may not work
|
|
+ if (hasFixedPitch(font)) {
|
|
return font;
|
|
}
|
|
- font.setFamily(QString::fromLatin1("courier"));
|
|
- if (font.fixedPitch()) {
|
|
- return font;
|
|
+ for (const char* family : {"Monospace", "Courier"}) {
|
|
+ font.setFamily(QString::fromLatin1(family));
|
|
+ if (hasFixedPitch(font)) {
|
|
+ return font;
|
|
+ }
|
|
}
|
|
- return font; // We failed, but return whatever we have anyway
|
|
+ return font;
|
|
}
|
|
+
|
|
} // namespace
|
|
|
|
/* TRANSLATOR Gui::Dialog::DlgSettingsEditor */
|
|
@@ -302,7 +309,7 @@ void DlgSettingsEditor::loadSettings()
|
|
ui->fontSize->setValue(10);
|
|
ui->fontSize->setValue(hGrp->GetInt("FontSize", ui->fontSize->value()));
|
|
|
|
- QByteArray defaultMonospaceFont = getMonospaceFont().family().toLatin1();
|
|
+ QByteArray defaultMonospaceFont = QFontInfo(getMonospaceFont()).family().toLatin1();
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
QStringList familyNames = QFontDatabase().families(QFontDatabase::Any);
|