From adbf4d7f68aa0e6abd15622b3f92c263b6403b94 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 19 Dec 2002 03:22:33 +0000 Subject: [PATCH] Fix default fonts in RH8.0. We use the style hint after all else fails in order to find a reasonable font. Note that StyleSerif does not work. I blame RedHat 8.0 personally, but cannot verify yet. Note also that in a sane world, we could just use font.setFamily(blah); QFontInfo(font).family() and set to that. But Qt is obviously not sane, so we stay with the weird setComboxFont() code we have :( git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5869 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 5 +++++ src/frontends/qt2/QPrefs.C | 33 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 3d823f556a..776c531377 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2002-12-19 John Levon + + * QPrefs.C: if we can't find the font family, use + StyleHint to get one close by + 2002-12-18 Alfredo Braunstein * QRef.C (redoRefs): small bug fix (wrong label was selected) diff --git a/src/frontends/qt2/QPrefs.C b/src/frontends/qt2/QPrefs.C index a09cac151f..b2e559a3e6 100644 --- a/src/frontends/qt2/QPrefs.C +++ b/src/frontends/qt2/QPrefs.C @@ -305,10 +305,9 @@ findPos(std::vector const & vec, A const & val) return std::distance(vec.begin(), it); } -void setComboxFont(QComboBox * cb, - string const & family, string const & foundry) +void setComboxFont(QComboBox * cb, string const & family, + string const & foundry, QFont::StyleHint hint) { - string const name = makeFontName(family, foundry); for (int i = 0; i < cb->count(); ++i) { if (fromqstr(cb->text(i)) == name) { @@ -318,14 +317,27 @@ void setComboxFont(QComboBox * cb, } // Try matching without foundary name + + // We count in reverse in order to prefer the Xft foundry for (int i = cb->count() - 1; i >= 0; --i) { - // We count in reverse in order to prefer the Xft foundry pair tmp = parseFontName(fromqstr(cb->text(i))); if (compare_no_case(tmp.first, family) == 0) { cb->setCurrentItem(i); return; } } + + // Try the hint + QFont font; + font.setStyleHint(hint); + QFontInfo fi(font); + + for (int i = cb->count() - 1; i >= 0; --i) { + if (cb->text(i) == fi.family()) { + cb->setCurrentItem(i); + return; + } + } } } @@ -411,6 +423,7 @@ void QPrefs::update_contents() case grfx::ColorDisplay: item = 2; break; case grfx::GrayscaleDisplay: item = 1; break; case grfx::MonochromeDisplay: item = 0; break; + default: break; } displaymod->displayGraphicsCO->setCurrentItem(item); @@ -465,12 +478,12 @@ void QPrefs::update_contents() QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule); - setComboxFont(fontmod->screenRomanCO, - rc.roman_font_name, rc.roman_font_foundry); - setComboxFont(fontmod->screenSansCO, - rc.sans_font_name, rc.sans_font_foundry); - setComboxFont(fontmod->screenTypewriterCO, - rc.typewriter_font_name, rc.typewriter_font_foundry); + setComboxFont(fontmod->screenRomanCO, rc.roman_font_name, + rc.roman_font_foundry, QFont::Serif); + setComboxFont(fontmod->screenSansCO, rc.sans_font_name, + rc.sans_font_foundry, QFont::SansSerif); + setComboxFont(fontmod->screenTypewriterCO, rc.typewriter_font_name, + rc.typewriter_font_foundry, QFont::TypeWriter); dialog_->select_roman(fontmod->screenRomanCO->currentText()); dialog_->select_sans(fontmod->screenSansCO->currentText()); -- 2.39.2