Skip to content

Commit

Permalink
Use the most regular/normal typeface style for preview purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Apr 9, 2024
1 parent 9bd0bf1 commit 7c7a04e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/app/ui/font_popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<set->count(); ++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;
Expand Down

0 comments on commit 7c7a04e

Please sign in to comment.