chore: add only-monospace font mode to exclude fonts as a failure source

This commit is contained in:
goaaats 2022-05-20 01:57:42 +02:00
parent 641c7d7fc0
commit 37cbdb7b3e
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 321 additions and 200 deletions

View file

@ -37,6 +37,11 @@ namespace Dalamud.Configuration.Internal
/// </summary> /// </summary>
public static bool DalamudDoContextMenu { get; } = GetEnvironmentVariable("DALAMUD_ENABLE_CONTEXTMENU"); public static bool DalamudDoContextMenu { get; } = GetEnvironmentVariable("DALAMUD_ENABLE_CONTEXTMENU");
/// <summary>
/// Gets a value indicating whether or not Dalamud context menus should be disabled.
/// </summary>
public static bool DalamudFontFallback { get; } = GetEnvironmentVariable("DALAMUD_FONT_FALLBACK");
private static bool GetEnvironmentVariable(string name) private static bool GetEnvironmentVariable(string name)
=> bool.Parse(Environment.GetEnvironmentVariable(name) ?? "false"); => bool.Parse(Environment.GetEnvironmentVariable(name) ?? "false");
} }

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Numerics; using System.Numerics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Dalamud.Configuration.Internal;
using Dalamud.Data; using Dalamud.Data;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using ImGuiNET; using ImGuiNET;
@ -315,6 +315,12 @@ namespace Dalamud.Interface.GameFonts
var font = io.Fonts.AddFontDefault(fontConfig); var font = io.Fonts.AddFontDefault(fontConfig);
if (EnvironmentConfiguration.DalamudFontFallback)
{
this.fonts[style] = InterfaceManager.MonoFont;
}
else
{
this.fonts[style] = font; this.fonts[style] = font;
foreach (var glyph in fdt.Glyphs) foreach (var glyph in fdt.Glyphs)
{ {
@ -334,6 +340,7 @@ namespace Dalamud.Interface.GameFonts
glyph); glyph);
} }
} }
}
fontConfig.Destroy(); fontConfig.Destroy();
} }

View file

@ -7,7 +7,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Game; using Dalamud.Game;
using Dalamud.Game.ClientState.GamePad; using Dalamud.Game.ClientState.GamePad;
@ -26,6 +25,8 @@ using ImGuiScene;
using PInvoke; using PInvoke;
using Serilog; using Serilog;
using SharpDX.Direct3D11; using SharpDX.Direct3D11;
using Silk.NET.SDL;
using Thread = System.Threading.Thread;
// general dev notes, here because it's easiest // general dev notes, here because it's easiest
/* /*
@ -49,7 +50,10 @@ namespace Dalamud.Interface.Internal
private const float MinimumFallbackFontSizePx = MinimumFallbackFontSizePt * 4.0f / 3.0f; private const float MinimumFallbackFontSizePx = MinimumFallbackFontSizePt * 4.0f / 3.0f;
private const float DefaultFontSizePt = 12.0f; private const float DefaultFontSizePt = 12.0f;
private const float DefaultFontSizePx = DefaultFontSizePt * 4.0f / 3.0f; private const float DefaultFontSizePx = DefaultFontSizePt * 4.0f / 3.0f;
private const ushort Fallback1Codepoint = 0x3013; // Geta mark; FFXIV uses this to indicate that a glyph is missing.
private const ushort
Fallback1Codepoint = 0x3013; // Geta mark; FFXIV uses this to indicate that a glyph is missing.
private const ushort Fallback2Codepoint = '-'; // FFXIV uses dash if Geta mark is unavailable. private const ushort Fallback2Codepoint = '-'; // FFXIV uses dash if Geta mark is unavailable.
private readonly string rtssPath; private readonly string rtssPath;
@ -105,9 +109,11 @@ namespace Dalamud.Interface.Internal
Log.Error(e, "RTSS Free failed"); Log.Error(e, "RTSS Free failed");
} }
this.setCursorHook = Hook<SetCursorDelegate>.FromSymbol("user32.dll", "SetCursor", this.SetCursorDetour, true); this.setCursorHook =
Hook<SetCursorDelegate>.FromSymbol("user32.dll", "SetCursor", this.SetCursorDetour, true);
this.presentHook = new Hook<PresentDelegate>(this.address.Present, this.PresentDetour); this.presentHook = new Hook<PresentDelegate>(this.address.Present, this.PresentDetour);
this.resizeBuffersHook = new Hook<ResizeBuffersDelegate>(this.address.ResizeBuffers, this.ResizeBuffersDetour); this.resizeBuffersHook =
new Hook<ResizeBuffersDelegate>(this.address.ResizeBuffers, this.ResizeBuffersDetour);
var setCursorAddress = this.setCursorHook?.Address ?? IntPtr.Zero; var setCursorAddress = this.setCursorHook?.Address ?? IntPtr.Zero;
@ -121,7 +127,8 @@ namespace Dalamud.Interface.Internal
private delegate IntPtr PresentDelegate(IntPtr swapChain, uint syncInterval, uint presentFlags); private delegate IntPtr PresentDelegate(IntPtr swapChain, uint syncInterval, uint presentFlags);
[UnmanagedFunctionPointer(CallingConvention.ThisCall)] [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate IntPtr ResizeBuffersDelegate(IntPtr swapChain, uint bufferCount, uint width, uint height, uint newFormat, uint swapChainFlags); private delegate IntPtr ResizeBuffersDelegate(
IntPtr swapChain, uint bufferCount, uint width, uint height, uint newFormat, uint swapChainFlags);
[UnmanagedFunctionPointer(CallingConvention.ThisCall)] [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate IntPtr SetCursorDelegate(IntPtr hCursor); private delegate IntPtr SetCursorDelegate(IntPtr hCursor);
@ -236,7 +243,9 @@ namespace Dalamud.Interface.Internal
/// <summary> /// <summary>
/// Gets the font gamma value to use. /// Gets the font gamma value to use.
/// </summary> /// </summary>
public float FontGamma => Math.Max(0.1f, this.FontGammaOverride.GetValueOrDefault(Service<DalamudConfiguration>.Get().FontGammaLevel)); public float FontGamma =>
Math.Max(
0.1f, this.FontGammaOverride.GetValueOrDefault(Service<DalamudConfiguration>.Get().FontGammaLevel));
/// <summary> /// <summary>
/// Gets or sets a value indicating whether to override configuration for FontResolutionLevel. /// Gets or sets a value indicating whether to override configuration for FontResolutionLevel.
@ -246,7 +255,8 @@ namespace Dalamud.Interface.Internal
/// <summary> /// <summary>
/// Gets a value indicating the level of font resolution. /// Gets a value indicating the level of font resolution.
/// </summary> /// </summary>
public int FontResolutionLevel => this.FontResolutionLevelOverride ?? Service<DalamudConfiguration>.Get().FontResolutionLevel; public int FontResolutionLevel =>
this.FontResolutionLevelOverride ?? Service<DalamudConfiguration>.Get().FontResolutionLevel;
/// <summary> /// <summary>
/// Enable this module. /// Enable this module.
@ -450,7 +460,9 @@ namespace Dalamud.Interface.Internal
private static void ShowFontError(string path) private static void ShowFontError(string path)
{ {
Util.Fatal($"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}", "Error"); Util.Fatal(
$"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}",
"Error");
} }
/* /*
@ -476,7 +488,8 @@ namespace Dalamud.Interface.Internal
IntPtr.Zero, IntPtr.Zero,
"Dalamud plugins require the Microsoft Visual C++ Redistributable to be installed.\nPlease install the runtime from the official Microsoft website or disable Dalamud.\n\nDo you want to download the redistributable now?", "Dalamud plugins require the Microsoft Visual C++ Redistributable to be installed.\nPlease install the runtime from the official Microsoft website or disable Dalamud.\n\nDo you want to download the redistributable now?",
"Dalamud Error", "Dalamud Error",
User32.MessageBoxOptions.MB_YESNO | User32.MessageBoxOptions.MB_TOPMOST | User32.MessageBoxOptions.MB_ICONERROR); User32.MessageBoxOptions.MB_YESNO | User32.MessageBoxOptions.MB_TOPMOST |
User32.MessageBoxOptions.MB_ICONERROR);
if (res == User32.MessageBoxResult.IDYES) if (res == User32.MessageBoxResult.IDYES)
{ {
@ -494,14 +507,16 @@ namespace Dalamud.Interface.Internal
var startInfo = Service<DalamudStartInfo>.Get(); var startInfo = Service<DalamudStartInfo>.Get();
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
var iniFileInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(startInfo.ConfigurationPath), "dalamudUI.ini")); var iniFileInfo =
new FileInfo(Path.Combine(Path.GetDirectoryName(startInfo.ConfigurationPath), "dalamudUI.ini"));
try try
{ {
if (iniFileInfo.Length > 1200000) if (iniFileInfo.Length > 1200000)
{ {
Log.Warning("dalamudUI.ini was over 1mb, deleting"); Log.Warning("dalamudUI.ini was over 1mb, deleting");
iniFileInfo.CopyTo(Path.Combine(iniFileInfo.DirectoryName, $"dalamudUI-{DateTimeOffset.Now.ToUnixTimeSeconds()}.ini")); iniFileInfo.CopyTo(Path.Combine(iniFileInfo.DirectoryName,
$"dalamudUI-{DateTimeOffset.Now.ToUnixTimeSeconds()}.ini"));
iniFileInfo.Delete(); iniFileInfo.Delete();
} }
} }
@ -518,9 +533,11 @@ namespace Dalamud.Interface.Internal
StyleModel.TransferOldModels(); StyleModel.TransferOldModels();
if (configuration.SavedStyles == null || configuration.SavedStyles.All(x => x.Name != StyleModelV1.DalamudStandard.Name)) if (configuration.SavedStyles == null ||
configuration.SavedStyles.All(x => x.Name != StyleModelV1.DalamudStandard.Name))
{ {
configuration.SavedStyles = new List<StyleModel> { StyleModelV1.DalamudStandard, StyleModelV1.DalamudClassic }; configuration.SavedStyles = new List<StyleModel>
{ StyleModelV1.DalamudStandard, StyleModelV1.DalamudClassic };
configuration.ChosenStyle = StyleModelV1.DalamudStandard.Name; configuration.ChosenStyle = StyleModelV1.DalamudStandard.Name;
} }
else if (configuration.SavedStyles.Count == 1) else if (configuration.SavedStyles.Count == 1)
@ -608,7 +625,8 @@ namespace Dalamud.Interface.Internal
{ {
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
if (configuration.IsDisableViewport || this.scene.SwapChain.IsFullScreen || ImGui.GetPlatformIO().Monitors.Size == 1) if (configuration.IsDisableViewport || this.scene.SwapChain.IsFullScreen ||
ImGui.GetPlatformIO().Monitors.Size == 1)
{ {
ImGui.GetIO().ConfigFlags &= ~ImGuiConfigFlags.ViewportsEnable; ImGui.GetIO().ConfigFlags &= ~ImGuiConfigFlags.ViewportsEnable;
return; return;
@ -623,6 +641,8 @@ namespace Dalamud.Interface.Internal
/// <param name="disableBigFonts">If set, then glyphs will be loaded in smaller resolution to make all glyphs fit into given constraints.</param> /// <param name="disableBigFonts">If set, then glyphs will be loaded in smaller resolution to make all glyphs fit into given constraints.</param>
private unsafe void SetupFonts(bool disableBigFonts = false) private unsafe void SetupFonts(bool disableBigFonts = false)
{ {
var onlyLoadMono = EnvironmentConfiguration.DalamudFontFallback;
var gameFontManager = Service<GameFontManager>.Get(); var gameFontManager = Service<GameFontManager>.Get();
var dalamud = Service<Dalamud>.Get(); var dalamud = Service<Dalamud>.Get();
var io = ImGui.GetIO(); var io = ImGui.GetIO();
@ -670,16 +690,63 @@ namespace Dalamud.Interface.Internal
fontPathKr = null; fontPathKr = null;
Log.Verbose("[FONT] fontPathKr = {0}", fontPathKr); Log.Verbose("[FONT] fontPathKr = {0}", fontPathKr);
if (onlyLoadMono)
{
// Monospace font
Log.Verbose("[FONT] SetupFonts - Monospace font");
{
var fontPathMono =
Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "Inconsolata-Regular.ttf");
if (!File.Exists(fontPathMono))
ShowFontError(fontPathMono);
fontConfig.GlyphRanges = IntPtr.Zero;
fontConfig.PixelSnapH = true;
MonoFont = ioFonts.AddFontFromFileTTF(fontPathMono,
disableBigFonts
? Math.Min(MinimumFallbackFontSizePx,
DefaultFontSizePx)
: DefaultFontSizePx * io.FontGlobalScale, fontConfig);
this.loadedFontInfo[MonoFont] = new("Mono", TargetFontModification.AxisMode.GameGlyphsOnly,
DefaultFontSizePx, io.FontGlobalScale, disableBigFonts);
DefaultFont = MonoFont;
IconFont = MonoFont;
Dictionary<float, List<SpecialGlyphRequest>> extraFontRequests = new();
foreach (var extraFontRequest in this.glyphRequests)
{
if (!extraFontRequests.ContainsKey(extraFontRequest.Size))
extraFontRequests[extraFontRequest.Size] = new();
extraFontRequests[extraFontRequest.Size].Add(extraFontRequest);
}
foreach (var (fontSize, requests) in extraFontRequests)
{
foreach (var request in requests)
{
request.FontInternal = MonoFont;
}
}
}
}
else
{
// Default font // Default font
Log.Verbose("[FONT] SetupFonts - Default font"); Log.Verbose("[FONT] SetupFonts - Default font");
var fontInfo = new TargetFontModification( var fontInfo = new TargetFontModification(
"Default", "Default",
this.UseAxis ? TargetFontModification.AxisMode.Overwrite : TargetFontModification.AxisMode.GameGlyphsOnly, this.UseAxis
? TargetFontModification.AxisMode.Overwrite
: TargetFontModification.AxisMode.GameGlyphsOnly,
this.UseAxis ? DefaultFontSizePx : DefaultFontSizePx + 1, this.UseAxis ? DefaultFontSizePx : DefaultFontSizePx + 1,
io.FontGlobalScale, io.FontGlobalScale,
disableBigFonts); disableBigFonts);
Log.Verbose("[FONT] SetupFonts - Default corresponding AXIS size: {0}pt ({1}px)", fontInfo.SourceAxis.Style.BaseSizePt, fontInfo.SourceAxis.Style.BaseSizePx); Log.Verbose("[FONT] SetupFonts - Default corresponding AXIS size: {0}pt ({1}px)",
fontConfig.SizePixels = disableBigFonts ? Math.Min(MinimumFallbackFontSizePx, fontInfo.TargetSizePx) : fontInfo.TargetSizePx * io.FontGlobalScale; fontInfo.SourceAxis.Style.BaseSizePt, fontInfo.SourceAxis.Style.BaseSizePx);
fontConfig.SizePixels = disableBigFonts
? Math.Min(MinimumFallbackFontSizePx, fontInfo.TargetSizePx)
: fontInfo.TargetSizePx * io.FontGlobalScale;
if (this.UseAxis) if (this.UseAxis)
{ {
fontConfig.GlyphRanges = dummyRangeHandle.AddrOfPinnedObject(); fontConfig.GlyphRanges = dummyRangeHandle.AddrOfPinnedObject();
@ -710,7 +777,8 @@ namespace Dalamud.Interface.Internal
// FontAwesome icon font // FontAwesome icon font
Log.Verbose("[FONT] SetupFonts - FontAwesome icon font"); Log.Verbose("[FONT] SetupFonts - FontAwesome icon font");
{ {
var fontPathIcon = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf"); var fontPathIcon =
Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf");
if (!File.Exists(fontPathIcon)) if (!File.Exists(fontPathIcon))
ShowFontError(fontPathIcon); ShowFontError(fontPathIcon);
@ -719,21 +787,32 @@ namespace Dalamud.Interface.Internal
fontConfig.GlyphRanges = iconRangeHandle.AddrOfPinnedObject(); fontConfig.GlyphRanges = iconRangeHandle.AddrOfPinnedObject();
fontConfig.PixelSnapH = true; fontConfig.PixelSnapH = true;
IconFont = ioFonts.AddFontFromFileTTF(fontPathIcon, disableBigFonts ? Math.Min(MinimumFallbackFontSizePx, DefaultFontSizePx) : DefaultFontSizePx * io.FontGlobalScale, fontConfig); IconFont = ioFonts.AddFontFromFileTTF(fontPathIcon,
this.loadedFontInfo[IconFont] = new("Icon", TargetFontModification.AxisMode.GameGlyphsOnly, DefaultFontSizePx, io.FontGlobalScale, disableBigFonts); disableBigFonts
? Math.Min(MinimumFallbackFontSizePx,
DefaultFontSizePx)
: DefaultFontSizePx * io.FontGlobalScale, fontConfig);
this.loadedFontInfo[IconFont] = new("Icon", TargetFontModification.AxisMode.GameGlyphsOnly,
DefaultFontSizePx, io.FontGlobalScale, disableBigFonts);
} }
// Monospace font // Monospace font
Log.Verbose("[FONT] SetupFonts - Monospace font"); Log.Verbose("[FONT] SetupFonts - Monospace font");
{ {
var fontPathMono = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "Inconsolata-Regular.ttf"); var fontPathMono =
Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "Inconsolata-Regular.ttf");
if (!File.Exists(fontPathMono)) if (!File.Exists(fontPathMono))
ShowFontError(fontPathMono); ShowFontError(fontPathMono);
fontConfig.GlyphRanges = IntPtr.Zero; fontConfig.GlyphRanges = IntPtr.Zero;
fontConfig.PixelSnapH = true; fontConfig.PixelSnapH = true;
MonoFont = ioFonts.AddFontFromFileTTF(fontPathMono, disableBigFonts ? Math.Min(MinimumFallbackFontSizePx, DefaultFontSizePx) : DefaultFontSizePx * io.FontGlobalScale, fontConfig); MonoFont = ioFonts.AddFontFromFileTTF(fontPathMono,
this.loadedFontInfo[MonoFont] = new("Mono", TargetFontModification.AxisMode.GameGlyphsOnly, DefaultFontSizePx, io.FontGlobalScale, disableBigFonts); disableBigFonts
? Math.Min(MinimumFallbackFontSizePx,
DefaultFontSizePx)
: DefaultFontSizePx * io.FontGlobalScale, fontConfig);
this.loadedFontInfo[MonoFont] = new("Mono", TargetFontModification.AxisMode.GameGlyphsOnly,
DefaultFontSizePx, io.FontGlobalScale, disableBigFonts);
} }
// Default font but in requested size for requested glyphs // Default font but in requested size for requested glyphs
@ -763,7 +842,11 @@ namespace Dalamud.Interface.Internal
codepointRanges.Add(range); codepointRanges.Add(range);
} }
codepointRanges.Sort((x, y) => (x.Item1 == y.Item1 ? (x.Item2 < y.Item2 ? -1 : (x.Item2 == y.Item2 ? 0 : 1)) : (x.Item1 < y.Item1 ? -1 : 1))); codepointRanges.Sort((x, y) => (x.Item1 == y.Item1
? (x.Item2 < y.Item2
? -1
: (x.Item2 == y.Item2 ? 0 : 1))
: (x.Item1 < y.Item1 ? -1 : 1)));
List<ushort> flattenedRanges = new(); List<ushort> flattenedRanges = new();
foreach (var range in codepointRanges) foreach (var range in codepointRanges)
@ -783,7 +866,9 @@ namespace Dalamud.Interface.Internal
fontInfo = new( fontInfo = new(
$"Requested({fontSize}px)", $"Requested({fontSize}px)",
this.UseAxis ? TargetFontModification.AxisMode.Overwrite : TargetFontModification.AxisMode.GameGlyphsOnly, this.UseAxis
? TargetFontModification.AxisMode.Overwrite
: TargetFontModification.AxisMode.GameGlyphsOnly,
fontSize, fontSize,
io.FontGlobalScale, io.FontGlobalScale,
disableBigFonts); disableBigFonts);
@ -804,13 +889,18 @@ namespace Dalamud.Interface.Internal
garbageList.Add(rangeHandle); garbageList.Add(rangeHandle);
fontConfig.PixelSnapH = true; fontConfig.PixelSnapH = true;
var sizedFont = ioFonts.AddFontFromFileTTF(fontPathJp, disableBigFonts ? Math.Min(MinimumFallbackFontSizePx, fontSize) : fontSize * io.FontGlobalScale, fontConfig, rangeHandle.AddrOfPinnedObject()); var sizedFont = ioFonts.AddFontFromFileTTF(
fontPathJp,
disableBigFonts
? Math.Min(MinimumFallbackFontSizePx, fontSize)
: fontSize * io.FontGlobalScale, fontConfig, rangeHandle.AddrOfPinnedObject());
this.loadedFontInfo[sizedFont] = fontInfo; this.loadedFontInfo[sizedFont] = fontInfo;
foreach (var request in requests) foreach (var request in requests)
request.FontInternal = sizedFont; request.FontInternal = sizedFont;
} }
} }
} }
}
gameFontManager.BuildFonts(disableBigFonts); gameFontManager.BuildFonts(disableBigFonts);
@ -880,13 +970,18 @@ namespace Dalamud.Interface.Internal
if (possibilityForScaling && !disableBigFonts) if (possibilityForScaling && !disableBigFonts)
{ {
Log.Information("[FONT] Atlas size is {0}x{1} which is bigger than allowed {2}x{3}. Retrying with minimized font sizes.", ioFonts.TexWidth, ioFonts.TexHeight, maxTexDimension, maxTexDimension); Log.Information(
"[FONT] Atlas size is {0}x{1} which is bigger than allowed {2}x{3}. Retrying with minimized font sizes.",
ioFonts.TexWidth, ioFonts.TexHeight, maxTexDimension, maxTexDimension);
this.SetupFonts(true); this.SetupFonts(true);
return; return;
} }
else else
{ {
Log.Warning("[FONT] Atlas size is {0}x{1} which is bigger than allowed {2}x{3} even when font sizes are minimized up to {4}px. This may result in crash.", ioFonts.TexWidth, ioFonts.TexHeight, maxTexDimension, maxTexDimension, MinimumFallbackFontSizePx); Log.Warning(
"[FONT] Atlas size is {0}x{1} which is bigger than allowed {2}x{3} even when font sizes are minimized up to {4}px. This may result in crash.",
ioFonts.TexWidth, ioFonts.TexHeight, maxTexDimension, maxTexDimension,
MinimumFallbackFontSizePx);
} }
} }
@ -900,6 +995,8 @@ namespace Dalamud.Interface.Internal
texPixels[i] = (byte)(Math.Pow(texPixels[i] / 255.0f, 1.0f / fontGamma) * 255.0f); texPixels[i] = (byte)(Math.Pow(texPixels[i] / 255.0f, 1.0f / fontGamma) * 255.0f);
} }
if (!onlyLoadMono)
{
gameFontManager.AfterBuildFonts(disableBigFonts); gameFontManager.AfterBuildFonts(disableBigFonts);
foreach (var (font, mod) in this.loadedFontInfo) foreach (var (font, mod) in this.loadedFontInfo)
@ -910,7 +1007,8 @@ namespace Dalamud.Interface.Internal
if (font.NativePtr != null && font.NativePtr->ConfigData != null) if (font.NativePtr != null && font.NativePtr->ConfigData != null)
{ {
var nameBytes = Encoding.UTF8.GetBytes($"{mod.Name}\0"); var nameBytes = Encoding.UTF8.GetBytes($"{mod.Name}\0");
Marshal.Copy(nameBytes, 0, (IntPtr)font.ConfigData.Name.Data, Math.Min(nameBytes.Length, font.ConfigData.Name.Count)); Marshal.Copy(nameBytes, 0, (IntPtr)font.ConfigData.Name.Data,
Math.Min(nameBytes.Length, font.ConfigData.Name.Count));
} }
} }
catch (NullReferenceException) catch (NullReferenceException)
@ -923,7 +1021,8 @@ namespace Dalamud.Interface.Internal
if (mod.Axis == TargetFontModification.AxisMode.Overwrite) if (mod.Axis == TargetFontModification.AxisMode.Overwrite)
{ {
Log.Verbose("[FONT] {0}: Overwrite from AXIS of size {1}px (was {2}px)", mod.Name, mod.SourceAxis.ImFont.FontSize, font.FontSize); Log.Verbose("[FONT] {0}: Overwrite from AXIS of size {1}px (was {2}px)", mod.Name,
mod.SourceAxis.ImFont.FontSize, font.FontSize);
font.FontSize = mod.SourceAxis.ImFont.FontSize; font.FontSize = mod.SourceAxis.ImFont.FontSize;
font.Ascent = mod.SourceAxis.ImFont.Ascent; font.Ascent = mod.SourceAxis.ImFont.Ascent;
font.Descent = mod.SourceAxis.ImFont.Descent; font.Descent = mod.SourceAxis.ImFont.Descent;
@ -933,20 +1032,24 @@ namespace Dalamud.Interface.Internal
} }
else if (mod.Axis == TargetFontModification.AxisMode.GameGlyphsOnly) else if (mod.Axis == TargetFontModification.AxisMode.GameGlyphsOnly)
{ {
Log.Verbose("[FONT] {0}: Overwrite game specific glyphs from AXIS of size {1}px", mod.Name, mod.SourceAxis.ImFont.FontSize, font.FontSize); Log.Verbose("[FONT] {0}: Overwrite game specific glyphs from AXIS of size {1}px", mod.Name,
mod.SourceAxis.ImFont.FontSize, font.FontSize);
if (!this.UseAxis && font.NativePtr == DefaultFont.NativePtr) if (!this.UseAxis && font.NativePtr == DefaultFont.NativePtr)
mod.SourceAxis.ImFont.FontSize -= 1; mod.SourceAxis.ImFont.FontSize -= 1;
GameFontManager.CopyGlyphsAcrossFonts(mod.SourceAxis.ImFont, font, true, false, 0xE020, 0xE0DB); GameFontManager.CopyGlyphsAcrossFonts(mod.SourceAxis.ImFont, font, true, false, 0xE020,
0xE0DB);
if (!this.UseAxis && font.NativePtr == DefaultFont.NativePtr) if (!this.UseAxis && font.NativePtr == DefaultFont.NativePtr)
mod.SourceAxis.ImFont.FontSize += 1; mod.SourceAxis.ImFont.FontSize += 1;
} }
Log.Verbose("[FONT] {0}: Resize from {1}px to {2}px", mod.Name, font.FontSize, mod.TargetSizePx); Log.Verbose("[FONT] {0}: Resize from {1}px to {2}px", mod.Name, font.FontSize,
mod.TargetSizePx);
GameFontManager.UnscaleFont(font, font.FontSize / mod.TargetSizePx, false); GameFontManager.UnscaleFont(font, font.FontSize / mod.TargetSizePx, false);
} }
// Fill missing glyphs in MonoFont from DefaultFont // Fill missing glyphs in MonoFont from DefaultFont
GameFontManager.CopyGlyphsAcrossFonts(DefaultFont, MonoFont, true, false); GameFontManager.CopyGlyphsAcrossFonts(DefaultFont, MonoFont, true, false);
}
for (int i = 0, i_ = ioFonts.Fonts.Size; i < i_; i++) for (int i = 0, i_ = ioFonts.Fonts.Size; i < i_; i++)
{ {
@ -964,8 +1067,7 @@ namespace Dalamud.Interface.Internal
this.fontBuildSignal.Set(); this.fontBuildSignal.Set();
this.FontsReady = true; this.FontsReady = true;
} } finally
finally
{ {
if (fontConfig.NativePtr != null) if (fontConfig.NativePtr != null)
fontConfig.Destroy(); fontConfig.Destroy();
@ -997,10 +1099,12 @@ namespace Dalamud.Interface.Internal
this.isRebuildingFonts = false; this.isRebuildingFonts = false;
} }
private IntPtr ResizeBuffersDetour(IntPtr swapChain, uint bufferCount, uint width, uint height, uint newFormat, uint swapChainFlags) private IntPtr ResizeBuffersDetour(
IntPtr swapChain, uint bufferCount, uint width, uint height, uint newFormat, uint swapChainFlags)
{ {
#if DEBUG #if DEBUG
Log.Verbose($"Calling resizebuffers swap@{swapChain.ToInt64():X}{bufferCount} {width} {height} {newFormat} {swapChainFlags}"); Log.Verbose(
$"Calling resizebuffers swap@{swapChain.ToInt64():X}{bufferCount} {width} {height} {newFormat} {swapChainFlags}");
#endif #endif
this.ResizeBuffers?.Invoke(); this.ResizeBuffers?.Invoke();
@ -1008,7 +1112,8 @@ namespace Dalamud.Interface.Internal
// We have to ensure we're working with the main swapchain, // We have to ensure we're working with the main swapchain,
// as viewports might be resizing as well // as viewports might be resizing as well
if (this.scene == null || swapChain != this.scene.SwapChain.NativePointer) if (this.scene == null || swapChain != this.scene.SwapChain.NativePointer)
return this.resizeBuffersHook.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags); return this.resizeBuffersHook.Original(swapChain, bufferCount, width, height, newFormat,
swapChainFlags);
this.scene?.OnPreResize(); this.scene?.OnPreResize();
@ -1025,7 +1130,8 @@ namespace Dalamud.Interface.Internal
private IntPtr SetCursorDetour(IntPtr hCursor) private IntPtr SetCursorDetour(IntPtr hCursor)
{ {
if (this.lastWantCapture == true && (!this.scene?.IsImGuiCursor(hCursor) ?? false) && this.OverrideGameCursor) if (this.lastWantCapture == true && (!this.scene?.IsImGuiCursor(hCursor) ?? false) &&
this.OverrideGameCursor)
return IntPtr.Zero; return IntPtr.Zero;
return this.setCursorHook.Original(hCursor); return this.setCursorHook.Original(hCursor);
@ -1196,13 +1302,16 @@ namespace Dalamud.Interface.Internal
/// <param name="sizePx">Target font size in pixels, which will not be considered for further scaling.</param> /// <param name="sizePx">Target font size in pixels, which will not be considered for further scaling.</param>
/// <param name="globalFontScale">Font scale to be referred for loading AXIS font of appropriate size.</param> /// <param name="globalFontScale">Font scale to be referred for loading AXIS font of appropriate size.</param>
/// <param name="disableBigFonts">Whether to enable loading big AXIS fonts.</param> /// <param name="disableBigFonts">Whether to enable loading big AXIS fonts.</param>
internal TargetFontModification(string name, AxisMode axis, float sizePx, float globalFontScale, bool disableBigFonts) internal TargetFontModification(
string name, AxisMode axis, float sizePx, float globalFontScale, bool disableBigFonts)
{ {
this.Name = name; this.Name = name;
this.Axis = axis; this.Axis = axis;
this.TargetSizePx = sizePx; this.TargetSizePx = sizePx;
this.Scale = disableBigFonts ? MinimumFallbackFontSizePx / sizePx : globalFontScale; this.Scale = disableBigFonts ? MinimumFallbackFontSizePx / sizePx : globalFontScale;
this.SourceAxis = Service<GameFontManager>.Get().NewFontRef(new(GameFontFamily.Axis, this.TargetSizePx * this.Scale)); this.SourceAxis = Service<GameFontManager>.Get()
.NewFontRef(
new(GameFontFamily.Axis, this.TargetSizePx * this.Scale));
} }
internal enum AxisMode internal enum AxisMode