mirror of https://github.com/aseprite/aseprite.git
Reset weight button when weight is not available, show weight in popup
This commit is contained in:
parent
dce1dfd06b
commit
1774d86939
|
@ -800,8 +800,12 @@ empty_fonts = No system fonts were found
|
||||||
[font_style]
|
[font_style]
|
||||||
antialias = Antialias
|
antialias = Antialias
|
||||||
hinting = Hinting
|
hinting = Hinting
|
||||||
|
hinting_none = No Hinting
|
||||||
|
hinting_slight = Slight Hinting
|
||||||
|
hinting_full = Full Hinting
|
||||||
ligatures = Ligatures
|
ligatures = Ligatures
|
||||||
font_weight = Font Weight
|
font_weight = Font Weight
|
||||||
|
italic = Italic
|
||||||
font_weight_100 = Thin
|
font_weight_100 = Thin
|
||||||
font_weight_200 = Extra Light
|
font_weight_200 = Extra Light
|
||||||
font_weight_300 = Light
|
font_weight_300 = Light
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "app/fonts/font_info.h"
|
#include "app/fonts/font_info.h"
|
||||||
|
|
||||||
#include "app/fonts/font_data.h"
|
#include "app/fonts/font_data.h"
|
||||||
|
#include "app/i18n/strings.h"
|
||||||
#include "app/pref/preferences.h"
|
#include "app/pref/preferences.h"
|
||||||
#include "base/fs.h"
|
#include "base/fs.h"
|
||||||
#include "base/split_string.h"
|
#include "base/split_string.h"
|
||||||
|
@ -142,19 +143,22 @@ std::string FontInfo::humanString() const
|
||||||
}
|
}
|
||||||
result += fmt::format(" {}pt", size());
|
result += fmt::format(" {}pt", size());
|
||||||
if (!result.empty()) {
|
if (!result.empty()) {
|
||||||
if (style().weight() >= text::FontStyle::Weight::SemiBold)
|
if (style().weight() != text::FontStyle::Weight::Normal)
|
||||||
result += " Bold";
|
result +=
|
||||||
|
" " +
|
||||||
|
Strings::Translate(
|
||||||
|
fmt::format("font_style.font_weight_{}", static_cast<int>(style().weight())).c_str());
|
||||||
if (style().slant() != text::FontStyle::Slant::Upright)
|
if (style().slant() != text::FontStyle::Slant::Upright)
|
||||||
result += " Italic";
|
result += " " + Strings::font_style_italic();
|
||||||
if (antialias())
|
if (antialias())
|
||||||
result += " Antialias";
|
result += " " + Strings::font_style_antialias();
|
||||||
if (ligatures())
|
if (ligatures())
|
||||||
result += " Ligatures";
|
result += " " + Strings::font_style_ligatures();
|
||||||
switch (hinting()) {
|
switch (hinting()) {
|
||||||
case text::FontHinting::None: result += " No Hinting"; break;
|
case text::FontHinting::None: result += " " + Strings::font_style_hinting(); break;
|
||||||
case text::FontHinting::Slight: result += " Slight Hinting"; break;
|
case text::FontHinting::Slight: result += " " + Strings::font_style_hinting_slight(); break;
|
||||||
case text::FontHinting::Normal: 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;
|
return result;
|
||||||
|
@ -222,7 +226,8 @@ app::FontInfo convert_to(const std::string& from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
text::FontStyle style(bold ? text::FontStyle::Weight::Bold : weight,
|
const text::FontStyle style(
|
||||||
|
bold ? text::FontStyle::Weight::Bold : weight,
|
||||||
text::FontStyle::Width::Normal,
|
text::FontStyle::Width::Normal,
|
||||||
italic ? text::FontStyle::Slant::Italic : text::FontStyle::Slant::Upright);
|
italic ? text::FontStyle::Slant::Italic : text::FontStyle::Slant::Upright);
|
||||||
|
|
||||||
|
|
|
@ -417,29 +417,41 @@ void FontEntry::setInfo(const FontInfo& info, const From fromField)
|
||||||
m_style.getItem(0)->setEnabled(false);
|
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) {
|
if (fromField != From::Face) {
|
||||||
m_face.setText(info.title());
|
m_face.setText(m_info.title());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromField != From::Size) {
|
if (fromField != From::Size) {
|
||||||
m_size.updateForFont(info);
|
m_size.updateForFont(m_info);
|
||||||
m_size.setValue(fmt::format("{}", info.size()));
|
m_size.setValue(fmt::format("{}", m_info.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_style.getItem(0)->setEnabled(hasBold);
|
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");
|
m_style.getItem(0)->setText("B");
|
||||||
|
|
||||||
// Give some indication of what the weight is, if we have any variation
|
// Give some indication of what the weight is, if we have any variation
|
||||||
if (m_style.getItem(0)->isSelected() && m_availableWeights.size() > 1) {
|
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+");
|
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-");
|
m_style.getItem(0)->setText("B-");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromField != From::Style) {
|
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);
|
FontChange(m_info, fromField);
|
||||||
|
@ -483,14 +495,14 @@ void FontEntry::onStyleItemClick(ButtonSet::Item* item)
|
||||||
auto currentWeight = m_info.style().weight();
|
auto currentWeight = m_info.style().weight();
|
||||||
|
|
||||||
auto weightChange = [this](text::FontStyle::Weight newWeight) {
|
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()),
|
setInfo(FontInfo(m_info, m_info.size(), style, m_info.flags(), m_info.hinting()),
|
||||||
From::Style);
|
From::Style);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto weight : m_availableWeights) {
|
for (auto weight : m_availableWeights) {
|
||||||
auto* menuItem = new MenuItem(Strings::Translate(
|
auto* menuItem = new MenuItem(Strings::Translate(
|
||||||
("font_style.font_weight_" + std::to_string(static_cast<int>(weight))).c_str()));
|
fmt::format("font_style.font_weight_{}", static_cast<int>(weight)).c_str()));
|
||||||
menuItem->setSelected(weight == currentWeight);
|
menuItem->setSelected(weight == currentWeight);
|
||||||
if (!menuItem->isSelected())
|
if (!menuItem->isSelected())
|
||||||
menuItem->Click.connect([&weightChange, weight] { weightChange(weight); });
|
menuItem->Click.connect([&weightChange, weight] { weightChange(weight); });
|
||||||
|
|
Loading…
Reference in New Issue