refactor(fonts): reuse Dalamud IconFontFixedWidthHandle for FontAwesome
Drop the custom NewDelegateFontHandle that built our own FontAwesome atlas slot and reuse Dalamud's UiBuilder.IconFontFixedWidthHandle instead. One less delegate-build step in the ctor, and the handle is host-managed so Dispose() leaves it alone. The pre-cycle icon inventory verified that every site we push the FontAwesome font for renders an icon that is present in the host's fixed-width handle glyph range, so no rendering site changes.
This commit is contained in:
+13
-16
@@ -13,15 +13,17 @@ namespace HellionChat;
|
|||||||
// AddFontWithFallback); a ctor-injected ILogger would not be reachable
|
// AddFontWithFallback); a ctor-injected ILogger would not be reachable
|
||||||
// from those scopes, so the class stays on Plugin.LogProxy.
|
// from those scopes, so the class stays on Plugin.LogProxy.
|
||||||
//
|
//
|
||||||
// Hybrid handle model: Axis, AxisItalic and FontAwesome are tied to the
|
// Hybrid handle model: Axis and AxisItalic mirror the game's current
|
||||||
// game's current font state and never change for the lifetime of the
|
// font state and are init-only. FontAwesome reuses Dalamud's UiBuilder
|
||||||
// plugin, so they are init-only. RegularFont and ItalicFont depend on
|
// fixed-width icon handle and is likewise init-only. RegularFont and
|
||||||
// user-toggleable settings and get replaced live via RebuildDelegateFonts
|
// ItalicFont depend on user-toggleable settings and get replaced live
|
||||||
// when those settings change; they stay as mutable nullable fields.
|
// via RebuildDelegateFonts when those settings change; they stay as
|
||||||
|
// mutable nullable fields.
|
||||||
//
|
//
|
||||||
// All five handles register inside a single SuppressAutoRebuild block in
|
// The four atlas-owned handles register inside a single
|
||||||
// the ctor so the font atlas only rebuilds once for the whole plugin start
|
// SuppressAutoRebuild block so the font atlas only rebuilds once for the
|
||||||
// instead of once per handle.
|
// whole plugin start instead of once per handle. FontAwesome lives
|
||||||
|
// outside that accounting because the UiBuilder already owns it.
|
||||||
public sealed class FontManager : IDisposable
|
public sealed class FontManager : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IDalamudPluginInterface _pluginInterface;
|
private readonly IDalamudPluginInterface _pluginInterface;
|
||||||
@@ -83,13 +85,7 @@ public sealed class FontManager : IDisposable
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
FontAwesome = atlas.NewDelegateFontHandle(e =>
|
FontAwesome = _pluginInterface.UiBuilder.IconFontFixedWidthHandle;
|
||||||
{
|
|
||||||
e.OnPreBuild(tk =>
|
|
||||||
tk.AddFontAwesomeIconFont(new SafeFontConfig { SizePx = GetFontSize() })
|
|
||||||
);
|
|
||||||
e.OnPostBuild(tk => tk.FitRatio(tk.Font));
|
|
||||||
});
|
|
||||||
|
|
||||||
RegularFont = BuildRegularFontHandle(atlas);
|
RegularFont = BuildRegularFontHandle(atlas);
|
||||||
|
|
||||||
@@ -181,7 +177,8 @@ public sealed class FontManager : IDisposable
|
|||||||
{
|
{
|
||||||
Axis.Dispose();
|
Axis.Dispose();
|
||||||
AxisItalic.Dispose();
|
AxisItalic.Dispose();
|
||||||
FontAwesome.Dispose();
|
// FontAwesome is shared with the UiBuilder; the host owns its
|
||||||
|
// lifetime, so the plugin must not dispose it.
|
||||||
RegularFont?.Dispose();
|
RegularFont?.Dispose();
|
||||||
ItalicFont?.Dispose();
|
ItalicFont?.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user