mirror of https://github.com/aseprite/aseprite.git
Fix bug ignoring bold/italic after we click another font name
If we clicked bold/italic, and then chose another font family, we were using the cached typeface inside the FontInfo instead of an update typeface with the selected styles applied (bold/italic). Now we don't cache the typeface inside FontInfo to avoid this.
This commit is contained in:
parent
53f045a369
commit
bc63d2f660
|
@ -25,14 +25,12 @@ FontInfo::FontInfo(Type type,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const float size,
|
const float size,
|
||||||
const text::FontStyle style,
|
const text::FontStyle style,
|
||||||
const bool antialias,
|
const bool antialias)
|
||||||
const text::TypefaceRef& typeface)
|
|
||||||
: m_type(type)
|
: m_type(type)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_size(size)
|
, m_size(size)
|
||||||
, m_style(style)
|
, m_style(style)
|
||||||
, m_antialias(antialias)
|
, m_antialias(antialias)
|
||||||
, m_typeface(typeface)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +43,6 @@ FontInfo::FontInfo(const FontInfo& other,
|
||||||
, m_size(size)
|
, m_size(size)
|
||||||
, m_style(style)
|
, m_style(style)
|
||||||
, m_antialias(antialias)
|
, m_antialias(antialias)
|
||||||
, m_typeface(other.typeface())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,18 +64,16 @@ std::string FontInfo::thumbnailId() const
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontInfo::findTypeface(const text::FontMgrRef& fontMgr) const
|
text::TypefaceRef FontInfo::findTypeface(const text::FontMgrRef& fontMgr) const
|
||||||
{
|
{
|
||||||
if (m_type != Type::System ||
|
if (m_type != Type::System)
|
||||||
m_typeface != nullptr) {
|
return nullptr;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const text::FontStyleSetRef set = fontMgr->matchFamily(m_name);
|
const text::FontStyleSetRef set = fontMgr->matchFamily(m_name);
|
||||||
if (set) {
|
if (set)
|
||||||
if (auto newTypeface = set->matchStyle(m_style))
|
return set->matchStyle(m_style);
|
||||||
m_typeface = newTypeface;
|
|
||||||
}
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|
|
@ -34,8 +34,7 @@ namespace app {
|
||||||
const std::string& name = {},
|
const std::string& name = {},
|
||||||
float size = kDefaultSize,
|
float size = kDefaultSize,
|
||||||
text::FontStyle style = text::FontStyle(),
|
text::FontStyle style = text::FontStyle(),
|
||||||
bool antialias = false,
|
bool antialias = false);
|
||||||
const text::TypefaceRef& typeface = nullptr);
|
|
||||||
|
|
||||||
FontInfo(const FontInfo& other,
|
FontInfo(const FontInfo& other,
|
||||||
float size,
|
float size,
|
||||||
|
@ -60,8 +59,7 @@ namespace app {
|
||||||
text::FontStyle style() const { return m_style; }
|
text::FontStyle style() const { return m_style; }
|
||||||
bool antialias() const { return m_antialias; }
|
bool antialias() const { return m_antialias; }
|
||||||
|
|
||||||
void findTypeface(const text::FontMgrRef& fontMgr) const;
|
text::TypefaceRef findTypeface(const text::FontMgrRef& fontMgr) const;
|
||||||
text::TypefaceRef typeface() const { return m_typeface; }
|
|
||||||
|
|
||||||
bool operator==(const FontInfo& other) const {
|
bool operator==(const FontInfo& other) const {
|
||||||
return (m_type == other.m_type &&
|
return (m_type == other.m_type &&
|
||||||
|
@ -76,7 +74,6 @@ namespace app {
|
||||||
float m_size = kDefaultSize;
|
float m_size = kDefaultSize;
|
||||||
text::FontStyle m_style;
|
text::FontStyle m_style;
|
||||||
bool m_antialias = false;
|
bool m_antialias = false;
|
||||||
mutable text::TypefaceRef m_typeface;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|
|
@ -78,12 +78,10 @@ public:
|
||||||
|
|
||||||
FontItem(const std::string& name,
|
FontItem(const std::string& name,
|
||||||
const text::FontStyle& style,
|
const text::FontStyle& style,
|
||||||
const text::FontStyleSetRef& set,
|
const text::FontStyleSetRef& set)
|
||||||
const text::TypefaceRef& typeface)
|
|
||||||
: ListItem(name)
|
: ListItem(name)
|
||||||
, m_fontInfo(FontInfo::Type::System, name,
|
, m_fontInfo(FontInfo::Type::System, name,
|
||||||
FontInfo::kDefaultSize,
|
FontInfo::kDefaultSize, style, true)
|
||||||
style, true, typeface)
|
|
||||||
, m_set(set) {
|
, m_set(set) {
|
||||||
getCachedThumbnail();
|
getCachedThumbnail();
|
||||||
}
|
}
|
||||||
|
@ -240,8 +238,7 @@ FontPopup::FontPopup(const FontInfo& fontInfo)
|
||||||
// weight, Upright slant, etc.)
|
// weight, Upright slant, etc.)
|
||||||
auto typeface = set->matchStyle(text::FontStyle());
|
auto typeface = set->matchStyle(text::FontStyle());
|
||||||
if (typeface) {
|
if (typeface) {
|
||||||
auto* item = new FontItem(name, typeface->fontStyle(),
|
auto* item = new FontItem(name, typeface->fontStyle(), set);
|
||||||
set, typeface);
|
|
||||||
item->ThumbnailGenerated.connect([this]{ onThumbnailGenerated(); });
|
item->ThumbnailGenerated.connect([this]{ onThumbnailGenerated(); });
|
||||||
m_listBox.addChild(item);
|
m_listBox.addChild(item);
|
||||||
empty = false;
|
empty = false;
|
||||||
|
|
|
@ -49,10 +49,10 @@ doc::ImageRef render_text(
|
||||||
|
|
||||||
if (fontInfo.type() == FontInfo::Type::System) {
|
if (fontInfo.type() == FontInfo::Type::System) {
|
||||||
// Just in case the typeface is not present in the FontInfo
|
// Just in case the typeface is not present in the FontInfo
|
||||||
fontInfo.findTypeface(fontMgr);
|
auto typeface = fontInfo.findTypeface(fontMgr);
|
||||||
|
|
||||||
const text::FontMgrRef fontMgr = theme->fontMgr();
|
const text::FontMgrRef fontMgr = theme->fontMgr();
|
||||||
font = fontMgr->makeFont(fontInfo.typeface());
|
font = fontMgr->makeFont(typeface);
|
||||||
if (!fontInfo.useDefaultSize())
|
if (!fontInfo.useDefaultSize())
|
||||||
font->setSize(fontInfo.size());
|
font->setSize(fontInfo.size());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue