diff --git a/data/strings/en.ini b/data/strings/en.ini index 4d47ffc50..15eb14839 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -800,8 +800,12 @@ empty_fonts = No system fonts were found [font_style] antialias = Antialias hinting = Hinting +hinting_none = No Hinting +hinting_slight = Slight Hinting +hinting_full = Full Hinting ligatures = Ligatures font_weight = Font Weight +italic = Italic font_weight_100 = Thin font_weight_200 = Extra Light font_weight_300 = Light diff --git a/src/app/fonts/font_info.cpp b/src/app/fonts/font_info.cpp index b5466c6f5..4b2ebce61 100644 --- a/src/app/fonts/font_info.cpp +++ b/src/app/fonts/font_info.cpp @@ -11,6 +11,7 @@ #include "app/fonts/font_info.h" #include "app/fonts/font_data.h" +#include "app/i18n/strings.h" #include "app/pref/preferences.h" #include "base/fs.h" #include "base/split_string.h" @@ -142,19 +143,22 @@ std::string FontInfo::humanString() const } result += fmt::format(" {}pt", size()); if (!result.empty()) { - if (style().weight() >= text::FontStyle::Weight::SemiBold) - result += " Bold"; + if (style().weight() != text::FontStyle::Weight::Normal) + result += + " " + + Strings::Translate( + fmt::format("font_style.font_weight_{}", static_cast(style().weight())).c_str()); if (style().slant() != text::FontStyle::Slant::Upright) - result += " Italic"; + result += " " + Strings::font_style_italic(); if (antialias()) - result += " Antialias"; + result += " " + Strings::font_style_antialias(); if (ligatures()) - result += " Ligatures"; + result += " " + Strings::font_style_ligatures(); switch (hinting()) { - case text::FontHinting::None: result += " No Hinting"; break; - case text::FontHinting::Slight: result += " Slight Hinting"; break; + case text::FontHinting::None: result += " " + Strings::font_style_hinting(); break; + case text::FontHinting::Slight: result += " " + Strings::font_style_hinting_slight(); break; case text::FontHinting::Normal: break; - case text::FontHinting::Full: result += " Full Hinting"; break; + case text::FontHinting::Full: result += " " + Strings::font_style_hinting_full(); break; } } return result; @@ -222,9 +226,10 @@ app::FontInfo convert_to(const std::string& from) } } - text::FontStyle style(bold ? text::FontStyle::Weight::Bold : weight, - text::FontStyle::Width::Normal, - italic ? text::FontStyle::Slant::Italic : text::FontStyle::Slant::Upright); + const text::FontStyle style( + bold ? text::FontStyle::Weight::Bold : weight, + text::FontStyle::Width::Normal, + italic ? text::FontStyle::Slant::Italic : text::FontStyle::Slant::Upright); return app::FontInfo(type, name, size, style, flags, hinting); } diff --git a/src/app/ui/font_entry.cpp b/src/app/ui/font_entry.cpp index f91a1712e..41704aa00 100644 --- a/src/app/ui/font_entry.cpp +++ b/src/app/ui/font_entry.cpp @@ -417,29 +417,41 @@ void FontEntry::setInfo(const FontInfo& info, const From fromField) m_style.getItem(0)->setEnabled(false); } + if (std::find(m_availableWeights.begin(), m_availableWeights.end(), m_info.style().weight()) == + m_availableWeights.end()) { + // The currently selected weight is not available, reset it back to normal. + m_info = app::FontInfo(m_info, + m_info.size(), + text::FontStyle(text::FontStyle::Weight::Normal, + m_info.style().width(), + m_info.style().slant()), + m_info.flags(), + m_info.hinting()); + } + if (fromField != From::Face) { - m_face.setText(info.title()); + m_face.setText(m_info.title()); } if (fromField != From::Size) { - m_size.updateForFont(info); - m_size.setValue(fmt::format("{}", info.size())); + m_size.updateForFont(m_info); + m_size.setValue(fmt::format("{}", m_info.size())); } m_style.getItem(0)->setEnabled(hasBold); - m_style.getItem(0)->setSelected(info.style().weight() != text::FontStyle::Weight::Normal); + m_style.getItem(0)->setSelected(m_info.style().weight() != text::FontStyle::Weight::Normal); m_style.getItem(0)->setText("B"); // Give some indication of what the weight is, if we have any variation if (m_style.getItem(0)->isSelected() && m_availableWeights.size() > 1) { - if (info.style().weight() > text::FontStyle::Weight::Bold) + if (m_info.style().weight() > text::FontStyle::Weight::Bold) m_style.getItem(0)->setText("B+"); - else if (info.style().weight() < text::FontStyle::Weight::Bold) + else if (m_info.style().weight() < text::FontStyle::Weight::Bold) m_style.getItem(0)->setText("B-"); } if (fromField != From::Style) { - m_style.getItem(1)->setSelected(info.style().slant() != text::FontStyle::Slant::Upright); + m_style.getItem(1)->setSelected(m_info.style().slant() != text::FontStyle::Slant::Upright); } FontChange(m_info, fromField); @@ -483,14 +495,14 @@ void FontEntry::onStyleItemClick(ButtonSet::Item* item) auto currentWeight = m_info.style().weight(); auto weightChange = [this](text::FontStyle::Weight newWeight) { - text::FontStyle style(newWeight, m_info.style().width(), m_info.style().slant()); + const text::FontStyle style(newWeight, m_info.style().width(), m_info.style().slant()); setInfo(FontInfo(m_info, m_info.size(), style, m_info.flags(), m_info.hinting()), From::Style); }; for (auto weight : m_availableWeights) { auto* menuItem = new MenuItem(Strings::Translate( - ("font_style.font_weight_" + std::to_string(static_cast(weight))).c_str())); + fmt::format("font_style.font_weight_{}", static_cast(weight)).c_str())); menuItem->setSelected(weight == currentWeight); if (!menuItem->isSelected()) menuItem->Click.connect([&weightChange, weight] { weightChange(weight); });