From 7c7a04e3c9d4d0dded4046ebd834b30eda84c1ca Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 26 Mar 2024 16:00:39 -0300 Subject: [PATCH] Use the most regular/normal typeface style for preview purposes --- src/app/ui/font_popup.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/app/ui/font_popup.cpp b/src/app/ui/font_popup.cpp index 2900533b698..e94404cf079 100644 --- a/src/app/ui/font_popup.cpp +++ b/src/app/ui/font_popup.cpp @@ -229,7 +229,28 @@ FontPopup::FontPopup(const FontInfo& fontInfo) std::string name = fontMgr->familyName(i); text::FontStyleSetRef set = fontMgr->familyStyleSet(i); if (set && set->count() > 0) { - auto* item = new FontItem(name, set->typeface(0)); + // Best style for preview purposes, i.e. the most regular + // style, without bold, italic, etc. + int best; + text::FontStyle bestStyle; + + for (int i=0; icount(); ++i) { + text::FontStyle style; + std::string subname; + set->getStyle(i, style, subname); + if ((i == 0) || + ((style.weight() == text::FontStyle::Weight::Normal && + bestStyle.weight() != text::FontStyle::Weight::Normal) || + (style.width() == text::FontStyle::Width::Normal && + bestStyle.width() != text::FontStyle::Width::Normal) || + (style.slant() == text::FontStyle::Slant::Upright && + bestStyle.slant() != text::FontStyle::Slant::Upright))) { + best = i; + bestStyle = style; + } + } + + auto* item = new FontItem(name, set->typeface(best)); item->ThumbnailGenerated.connect([this]{ onThumbnailGenerated(); }); m_listBox.addChild(item); empty = false;