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:
David Capello 2024-04-15 19:02:07 -03:00
parent 53f045a369
commit bc63d2f660
4 changed files with 15 additions and 26 deletions

View File

@ -25,14 +25,12 @@ FontInfo::FontInfo(Type type,
const std::string& name,
const float size,
const text::FontStyle style,
const bool antialias,
const text::TypefaceRef& typeface)
const bool antialias)
: m_type(type)
, m_name(name)
, m_size(size)
, m_style(style)
, m_antialias(antialias)
, m_typeface(typeface)
{
}
@ -45,7 +43,6 @@ FontInfo::FontInfo(const FontInfo& other,
, m_size(size)
, m_style(style)
, m_antialias(antialias)
, m_typeface(other.typeface())
{
}
@ -67,18 +64,16 @@ std::string FontInfo::thumbnailId() const
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 ||
m_typeface != nullptr) {
return;
}
if (m_type != Type::System)
return nullptr;
const text::FontStyleSetRef set = fontMgr->matchFamily(m_name);
if (set) {
if (auto newTypeface = set->matchStyle(m_style))
m_typeface = newTypeface;
}
if (set)
return set->matchStyle(m_style);
return nullptr;
}
} // namespace app

View File

@ -34,8 +34,7 @@ namespace app {
const std::string& name = {},
float size = kDefaultSize,
text::FontStyle style = text::FontStyle(),
bool antialias = false,
const text::TypefaceRef& typeface = nullptr);
bool antialias = false);
FontInfo(const FontInfo& other,
float size,
@ -60,8 +59,7 @@ namespace app {
text::FontStyle style() const { return m_style; }
bool antialias() const { return m_antialias; }
void findTypeface(const text::FontMgrRef& fontMgr) const;
text::TypefaceRef typeface() const { return m_typeface; }
text::TypefaceRef findTypeface(const text::FontMgrRef& fontMgr) const;
bool operator==(const FontInfo& other) const {
return (m_type == other.m_type &&
@ -76,7 +74,6 @@ namespace app {
float m_size = kDefaultSize;
text::FontStyle m_style;
bool m_antialias = false;
mutable text::TypefaceRef m_typeface;
};
} // namespace app

View File

@ -78,12 +78,10 @@ public:
FontItem(const std::string& name,
const text::FontStyle& style,
const text::FontStyleSetRef& set,
const text::TypefaceRef& typeface)
const text::FontStyleSetRef& set)
: ListItem(name)
, m_fontInfo(FontInfo::Type::System, name,
FontInfo::kDefaultSize,
style, true, typeface)
FontInfo::kDefaultSize, style, true)
, m_set(set) {
getCachedThumbnail();
}
@ -240,8 +238,7 @@ FontPopup::FontPopup(const FontInfo& fontInfo)
// weight, Upright slant, etc.)
auto typeface = set->matchStyle(text::FontStyle());
if (typeface) {
auto* item = new FontItem(name, typeface->fontStyle(),
set, typeface);
auto* item = new FontItem(name, typeface->fontStyle(), set);
item->ThumbnailGenerated.connect([this]{ onThumbnailGenerated(); });
m_listBox.addChild(item);
empty = false;

View File

@ -49,10 +49,10 @@ doc::ImageRef render_text(
if (fontInfo.type() == FontInfo::Type::System) {
// 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();
font = fontMgr->makeFont(fontInfo.typeface());
font = fontMgr->makeFont(typeface);
if (!fontInfo.useDefaultSize())
font->setSize(fontInfo.size());
}