mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-27 02:49:18 +01:00
Implement feature to use game resource fonts
This commit is contained in:
parent
b7c47b4c97
commit
f3588dfe23
9 changed files with 1137 additions and 2 deletions
|
|
@ -16,6 +16,7 @@ using Dalamud.Game.Gui.Internal;
|
|||
using Dalamud.Game.Internal.DXGI;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Hooking.Internal;
|
||||
using Dalamud.Interface.GameFonts;
|
||||
using Dalamud.Interface.Internal.ManagedAsserts;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using Dalamud.Interface.Internal.Windows.StyleEditor;
|
||||
|
|
@ -56,6 +57,9 @@ namespace Dalamud.Interface.Internal
|
|||
private readonly SwapChainVtableResolver address;
|
||||
private RawDX11Scene? scene;
|
||||
|
||||
private GameFont overwriteDefaultFontFromGameFont = GameFont.Undefined;
|
||||
private GameFontHandle? overwriteDefaultFontFromGameFontHandle;
|
||||
|
||||
// can't access imgui IO before first present call
|
||||
private bool lastWantCapture = false;
|
||||
private bool isRebuildingFonts = false;
|
||||
|
|
@ -128,10 +132,15 @@ namespace Dalamud.Interface.Internal
|
|||
public event Action ResizeBuffers;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an action that is executed when fonts are rebuilt.
|
||||
/// Gets or sets an action that is executed right before fonts are rebuilt.
|
||||
/// </summary>
|
||||
public event Action BuildFonts;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an action that is executed right after fonts are rebuilt.
|
||||
/// </summary>
|
||||
public event Action AfterBuildFonts;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default ImGui font.
|
||||
/// </summary>
|
||||
|
|
@ -304,6 +313,16 @@ namespace Dalamud.Interface.Internal
|
|||
if (!this.isRebuildingFonts)
|
||||
{
|
||||
Log.Verbose("[FONT] RebuildFonts() trigger");
|
||||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
if (this.overwriteDefaultFontFromGameFont != configuration.DefaultFontFromGame)
|
||||
{
|
||||
this.overwriteDefaultFontFromGameFont = configuration.DefaultFontFromGame;
|
||||
this.overwriteDefaultFontFromGameFontHandle?.Dispose();
|
||||
if (configuration.DefaultFontFromGame == GameFont.Undefined)
|
||||
this.overwriteDefaultFontFromGameFontHandle = null;
|
||||
else
|
||||
this.overwriteDefaultFontFromGameFontHandle = Service<GameFontManager>.Get().NewFontRef(configuration.DefaultFontFromGame);
|
||||
}
|
||||
|
||||
this.isRebuildingFonts = true;
|
||||
this.scene.OnNewRenderFrame += this.RebuildFontsInternal;
|
||||
|
|
@ -384,6 +403,16 @@ namespace Dalamud.Interface.Internal
|
|||
this.scene.OnBuildUI += this.Display;
|
||||
this.scene.OnNewInputFrame += this.OnNewInputFrame;
|
||||
|
||||
if (this.overwriteDefaultFontFromGameFont != configuration.DefaultFontFromGame)
|
||||
{
|
||||
this.overwriteDefaultFontFromGameFont = configuration.DefaultFontFromGame;
|
||||
this.overwriteDefaultFontFromGameFontHandle?.Dispose();
|
||||
if (configuration.DefaultFontFromGame == GameFont.Undefined)
|
||||
this.overwriteDefaultFontFromGameFontHandle = null;
|
||||
else
|
||||
this.overwriteDefaultFontFromGameFontHandle = Service<GameFontManager>.Get().NewFontRef(configuration.DefaultFontFromGame);
|
||||
}
|
||||
|
||||
this.SetupFonts();
|
||||
|
||||
StyleModel.TransferOldModels();
|
||||
|
|
@ -496,7 +525,6 @@ namespace Dalamud.Interface.Internal
|
|||
ImGui.GetIO().Fonts.Clear();
|
||||
|
||||
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
|
||||
fontConfig.MergeMode = true;
|
||||
fontConfig.PixelSnapH = true;
|
||||
|
||||
var fontPathJp = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf");
|
||||
|
|
@ -522,7 +550,9 @@ namespace Dalamud.Interface.Internal
|
|||
},
|
||||
GCHandleType.Pinned);
|
||||
|
||||
fontConfig.MergeMode = false;
|
||||
ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, gameRangeHandle.AddrOfPinnedObject());
|
||||
fontConfig.MergeMode = true;
|
||||
|
||||
var fontPathIcon = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf");
|
||||
|
||||
|
|
@ -546,6 +576,9 @@ namespace Dalamud.Interface.Internal
|
|||
|
||||
MonoFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathMono, 16.0f);
|
||||
|
||||
var gameFontManager = Service<GameFontManager>.Get();
|
||||
gameFontManager.BuildFonts();
|
||||
|
||||
Log.Verbose("[FONT] Invoke OnBuildFonts");
|
||||
this.BuildFonts?.Invoke();
|
||||
Log.Verbose("[FONT] OnBuildFonts OK!");
|
||||
|
|
@ -557,6 +590,13 @@ namespace Dalamud.Interface.Internal
|
|||
|
||||
ImGui.GetIO().Fonts.Build();
|
||||
|
||||
gameFontManager.AfterBuildFonts();
|
||||
GameFontManager.CopyGlyphsAcrossFonts(this.overwriteDefaultFontFromGameFontHandle?.Get(), DefaultFont, false, true);
|
||||
|
||||
Log.Verbose("[FONT] Invoke OnAfterBuildFonts");
|
||||
this.AfterBuildFonts?.Invoke();
|
||||
Log.Verbose("[FONT] OnAfterBuildFonts OK!");
|
||||
|
||||
Log.Verbose("[FONT] Fonts built!");
|
||||
|
||||
this.fontBuildSignal.Set();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue