fix Font and FontAsset cache not completely refreshed when options change
This commit is contained in:
@@ -141,7 +141,6 @@ namespace FlaxEditor.Windows.Assets
|
||||
if (assetOptions != options)
|
||||
{
|
||||
Asset.Options = options;
|
||||
Asset.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,21 @@ void Font::CacheText(const StringView& text)
|
||||
}
|
||||
}
|
||||
|
||||
void Font::Invalidate()
|
||||
{
|
||||
ScopeLock lock(_asset->Locker);
|
||||
|
||||
FlushFaceSize();
|
||||
const FT_Face face = _asset->GetFTFace();
|
||||
ASSERT(face != nullptr);
|
||||
_height = Convert26Dot6ToRoundedPixel<int32>(FT_MulFix(face->height, face->size->metrics.y_scale));
|
||||
_hasKerning = FT_HAS_KERNING(face) != 0;
|
||||
_ascender = Convert26Dot6ToRoundedPixel<int16>(face->size->metrics.ascender);
|
||||
_descender = Convert26Dot6ToRoundedPixel<int16>(face->size->metrics.descender);
|
||||
_lineGap = _height - _ascender + _descender;
|
||||
_kerningTable.Clear();
|
||||
}
|
||||
|
||||
void Font::ProcessText(const StringView& text, Array<FontLineCache, InlinedAllocation<8>>& outputLines, const TextLayoutOptions& layout)
|
||||
{
|
||||
int32 textLength = text.Length();
|
||||
@@ -463,8 +478,7 @@ void Font::FlushFaceSize() const
|
||||
{
|
||||
// Set the character size
|
||||
const FT_Face face = _asset->GetFTFace();
|
||||
FontOptions options = _asset->GetOptions();
|
||||
float size = options.RasterMode == FontRasterMode::MSDF ? options.MSDFSize : _size;
|
||||
float size = _asset->GetOptions().RasterMode == FontRasterMode::MSDF ? _asset->GetOptions().MSDFSize : _size;
|
||||
const FT_Error error = FT_Set_Char_Size(face, 0, ConvertPixelTo26Dot6<FT_F26Dot6>(size * FontManager::FontScale), DefaultDPI, DefaultDPI);
|
||||
if (error)
|
||||
{
|
||||
|
||||
@@ -228,6 +228,11 @@ public:
|
||||
/// <param name="text">The text witch characters to cache.</param>
|
||||
API_FUNCTION() void CacheText(const StringView& text);
|
||||
|
||||
/// <summary>
|
||||
/// Refresh cached metrics. Can be used after changing font asset options.
|
||||
/// </summary>
|
||||
API_FUNCTION() void Invalidate();
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Processes text to get cached lines for rendering.
|
||||
|
||||
@@ -101,6 +101,26 @@ FontFlags FontAsset::GetStyle() const
|
||||
void FontAsset::SetOptions(const FontOptions& value)
|
||||
{
|
||||
_options = value;
|
||||
Invalidate();
|
||||
|
||||
if (_virtualBold)
|
||||
{
|
||||
auto options = _options;
|
||||
options.Flags |= FontFlags::Bold;
|
||||
_virtualBold->SetOptions(options);
|
||||
}
|
||||
if (_virtualItalic)
|
||||
{
|
||||
auto options = _options;
|
||||
options.Flags |= FontFlags::Italic;
|
||||
_virtualItalic->SetOptions(options);
|
||||
}
|
||||
if (_virtualMSDF)
|
||||
{
|
||||
auto options = _options;
|
||||
options.RasterMode = FontRasterMode::MSDF;
|
||||
_virtualMSDF->SetOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
Font* FontAsset::CreateFont(float size)
|
||||
@@ -218,6 +238,10 @@ void FontAsset::Invalidate()
|
||||
FontManager::Invalidate(entry.Value);
|
||||
|
||||
_characterCache.Clear();
|
||||
|
||||
// Refresh cached metrics of all fonts created from this asset
|
||||
for (auto font : _fonts)
|
||||
font->Invalidate();
|
||||
}
|
||||
|
||||
uint64 FontAsset::GetMemoryUsage() const
|
||||
|
||||
Reference in New Issue
Block a user