Merge branch 'imgui-bindings' into api13

# Conflicts:
#	Dalamud/Game/Gui/GameGui.cs
#	Dalamud/Interface/Internal/UiDebug.cs
#	Dalamud/Interface/Internal/Windows/Data/Widgets/AddonWidget.cs
#	Dalamud/Interface/Internal/Windows/SelfTest/Steps/ItemPayloadSelfTestStep.cs
This commit is contained in:
Kaz Wolfe 2025-08-04 11:30:14 -07:00
commit bd52c60c6f
No known key found for this signature in database
GPG key ID: 258813F53A16EBB4
1006 changed files with 1126138 additions and 4022 deletions

View file

@ -1,12 +1,11 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility;
using Dalamud.Logging.Internal;
using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
/// <summary>
@ -159,7 +158,7 @@ internal sealed class DelegateFontHandle : FontHandle
{
toolkitPreBuild.Font = default;
k.CallOnBuildStepChange(toolkitPreBuild);
if (toolkitPreBuild.Font.IsNull())
if (toolkitPreBuild.Font.IsNull)
{
if (fontCountPrevious == fontsVector.Length)
{
@ -177,7 +176,7 @@ internal sealed class DelegateFontHandle : FontHandle
{
for (var i = fontCountPrevious; !found && i < fontsVector.Length; i++)
{
if (fontsVector[i].NativePtr == toolkitPreBuild.Font.NativePtr)
if (fontsVector[i].Handle == toolkitPreBuild.Font.Handle)
found = true;
}
}
@ -223,7 +222,7 @@ internal sealed class DelegateFontHandle : FontHandle
{
unsafe
{
if (fontsVector[i].NativePtr == fontsVector[j].NativePtr)
if (fontsVector[i].Handle == fontsVector[j].Handle)
throw new InvalidOperationException("An already added font has been added again.");
}
}
@ -247,7 +246,7 @@ internal sealed class DelegateFontHandle : FontHandle
{
var distinct =
fontsVector
.DistinctBy(x => (nint)x.NativePtr) // Remove duplicates
.DistinctBy(x => (nint)x.Handle) // Remove duplicates
.Where(x => x.ValidateUnsafe() is null) // Remove invalid entries without freeing them
.ToArray();

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Bindings.ImGui;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.FontIdentifier;
using Dalamud.Interface.GameFonts;
@ -14,11 +15,7 @@ using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Utility;
using Dalamud.Storage.Assets;
using Dalamud.Utility;
using ImGuiNET;
using SharpDX.DXGI;
using TerraFX.Interop.DirectX;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
@ -119,7 +116,7 @@ internal sealed partial class FontAtlasFactory
foreach (var s in this.data.Substances)
{
var f = s.GetFontPtr(fontHandle);
if (!f.IsNull())
if (!f.IsNull)
return f;
}
@ -155,7 +152,7 @@ internal sealed partial class FontAtlasFactory
Log.Verbose(
"[{name}] 0x{atlas:X}: {funcname}(0x{dataPointer:X}, 0x{dataSize:X}, ...) from {tag}",
this.data.Owner?.Name ?? "(error)",
(nint)this.NewImAtlas.NativePtr,
(nint)this.NewImAtlas.Handle,
nameof(this.AddFontFromImGuiHeapAllocatedMemory),
(nint)dataPointer,
dataSize,
@ -169,7 +166,7 @@ internal sealed partial class FontAtlasFactory
var raw = fontConfig.Raw with
{
FontData = dataPointer,
FontDataOwnedByAtlas = 1,
FontDataOwnedByAtlas = true,
FontDataSize = dataSize,
};
@ -181,7 +178,7 @@ internal sealed partial class FontAtlasFactory
TrueTypeUtils.CheckImGuiCompatibleOrThrow(raw);
font = this.NewImAtlas.AddFont(&raw);
font = this.NewImAtlas.AddFont(raw);
var dataHash = default(HashCode);
dataHash.AddBytes(new(dataPointer, dataSize));
@ -218,11 +215,11 @@ internal sealed partial class FontAtlasFactory
}
catch
{
if (!font.IsNull())
if (!font.IsNull)
{
// Note that for both RemoveAt calls, corresponding destructors will be called.
var configIndex = this.data.ConfigData.FindIndex(x => x.DstFont == font.NativePtr);
var configIndex = this.data.ConfigData.FindIndex(x => x.DstFont == font.Handle);
if (configIndex >= 0)
this.data.ConfigData.RemoveAt(configIndex);
@ -233,7 +230,7 @@ internal sealed partial class FontAtlasFactory
// ImFontConfig has no destructor, and does not free the data.
if (freeOnException)
ImGuiNative.igMemFree(dataPointer);
ImGui.MemFree(dataPointer);
throw;
}
@ -265,21 +262,21 @@ internal sealed partial class FontAtlasFactory
stream = ms;
}
var length = checked((int)(uint)stream.Length);
var length = checked((uint)stream.Length);
var memory = ImGuiHelpers.AllocateMemory(length);
try
{
stream.ReadExactly(new(memory, length));
stream.ReadExactly(new(memory, checked((int)length)));
return this.AddFontFromImGuiHeapAllocatedMemory(
memory,
length,
checked((int)length),
fontConfig,
false,
$"{nameof(this.AddFontFromStream)}({debugTag})");
}
catch
{
ImGuiNative.igMemFree(memory);
ImGui.MemFree(memory);
throw;
}
}
@ -291,7 +288,7 @@ internal sealed partial class FontAtlasFactory
string debugTag)
{
var length = span.Length;
var memory = ImGuiHelpers.AllocateMemory(length);
var memory = ImGuiHelpers.AllocateMemory(checked((uint)length));
try
{
span.CopyTo(new(memory, length));
@ -304,7 +301,7 @@ internal sealed partial class FontAtlasFactory
}
catch
{
ImGuiNative.igMemFree(memory);
ImGui.MemFree(memory);
throw;
}
}
@ -334,14 +331,14 @@ internal sealed partial class FontAtlasFactory
}
}
if (font.IsNull())
if (font.IsNull)
{
// fall back to AXIS fonts
font = this.AddGameGlyphs(new(GameFontFamily.Axis, sizePx), glyphRanges, default);
}
this.AttachExtraGlyphsForDalamudLanguage(new() { SizePx = sizePx, MergeFont = font });
if (this.Font.IsNull())
if (this.Font.IsNull)
this.Font = font;
return font;
}
@ -416,9 +413,9 @@ internal sealed partial class FontAtlasFactory
int style = (int)DWRITE_FONT_STYLE.DWRITE_FONT_STYLE_NORMAL)
{
var targetFont = fontConfig.MergeFont;
if (targetFont.IsNull())
if (targetFont.IsNull)
targetFont = this.Font;
if (targetFont.IsNull())
if (targetFont.IsNull)
return;
// https://learn.microsoft.com/en-us/windows/apps/design/globalizing/loc-international-fonts
@ -559,9 +556,9 @@ internal sealed partial class FontAtlasFactory
public void AttachExtraGlyphsForDalamudLanguage(in SafeFontConfig fontConfig)
{
var targetFont = fontConfig.MergeFont;
if (targetFont.IsNull())
if (targetFont.IsNull)
targetFont = this.Font;
if (targetFont.IsNull())
if (targetFont.IsNull)
return;
var dalamudConfiguration = Service<DalamudConfiguration>.Get();
@ -653,7 +650,7 @@ internal sealed partial class FontAtlasFactory
foreach (var c in FallbackCodepoints)
{
var g = font.FindGlyphNoFallback(c);
if (g.NativePtr == null)
if (g == null)
continue;
font.UpdateFallbackChar(c);
@ -663,7 +660,7 @@ internal sealed partial class FontAtlasFactory
foreach (var c in EllipsisCodepoints)
{
var g = font.FindGlyphNoFallback(c);
if (g.NativePtr == null)
if (g == null)
continue;
font.EllipsisChar = c;
@ -699,8 +696,8 @@ internal sealed partial class FontAtlasFactory
{
ref var texture = ref textureSpan[i];
var name =
$"{nameof(FontAtlasBuiltData)}[{this.data.Owner?.Name ?? "-"}][0x{(long)this.data.Atlas.NativePtr:X}][{i}]";
if (texture.TexID != 0)
$"{nameof(FontAtlasBuiltData)}[{this.data.Owner?.Name ?? "-"}][0x{(long)this.data.Atlas.Handle:X}][{i}]";
if (!texture.TexID.IsNull)
{
// Nothing to do
}
@ -712,7 +709,7 @@ internal sealed partial class FontAtlasFactory
name);
this.factory.TextureManager.Blame(wrap, this.data.Owner?.OwnerPlugin);
this.data.AddExistingTexture(wrap);
texture.TexID = wrap.ImGuiHandle;
texture.TexID = wrap.Handle;
}
else if (texture.TexPixelsAlpha8 is not null)
{
@ -758,7 +755,7 @@ internal sealed partial class FontAtlasFactory
name);
this.factory.TextureManager.Blame(wrap, this.data.Owner?.OwnerPlugin);
this.data.AddExistingTexture(wrap);
texture.TexID = wrap.ImGuiHandle;
texture.TexID = wrap.Handle;
continue;
}
else
@ -769,9 +766,9 @@ internal sealed partial class FontAtlasFactory
}
if (texture.TexPixelsRGBA32 is not null)
ImGuiNative.igMemFree(texture.TexPixelsRGBA32);
ImGui.MemFree(texture.TexPixelsRGBA32);
if (texture.TexPixelsAlpha8 is not null)
ImGuiNative.igMemFree(texture.TexPixelsAlpha8);
ImGui.MemFree(texture.TexPixelsAlpha8);
texture.TexPixelsRGBA32 = null;
texture.TexPixelsAlpha8 = null;
}
@ -795,8 +792,8 @@ internal sealed partial class FontAtlasFactory
var targetFound = false;
foreach (var f in this.Fonts)
{
sourceFound |= f.NativePtr == source.NativePtr;
targetFound |= f.NativePtr == target.NativePtr;
sourceFound |= f.Handle == source.Handle;
targetFound |= f.Handle == target.Handle;
}
if (sourceFound && targetFound)
@ -817,8 +814,8 @@ internal sealed partial class FontAtlasFactory
public unsafe void BuildLookupTable(ImFontPtr font)
{
// Need to clear previous Fallback pointers before BuildLookupTable, or it may crash
font.NativePtr->FallbackGlyph = null;
font.NativePtr->FallbackHotData = null;
font.Handle->FallbackGlyph = null;
font.Handle->FallbackHotData = null;
font.BuildLookupTable();
// Need to fix our custom ImGui, so that imgui_widgets.cpp:3656 stops thinking
@ -826,7 +823,7 @@ internal sealed partial class FontAtlasFactory
// Otherwise, having a fallback character in ImGui.InputText gets strange.
var indexedHotData = font.IndexedHotDataWrapped();
var indexLookup = font.IndexLookupWrapped();
ref var fallbackHotData = ref *(ImGuiHelpers.ImFontGlyphHotDataReal*)font.NativePtr->FallbackHotData;
ref var fallbackHotData = ref *(ImGuiHelpers.ImFontGlyphHotDataReal*)font.Handle->FallbackHotData;
for (var codepoint = 0; codepoint < indexedHotData.Length; codepoint++)
{
if (indexLookup[codepoint] == ushort.MaxValue)

View file

@ -8,16 +8,14 @@ using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Utility;
using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
using ImGuiNET;
using JetBrains.Annotations;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
@ -74,12 +72,12 @@ internal sealed partial class FontAtlasFactory
var wrapsCopy = this.wraps = new();
this.Garbage.Add(() => wrapsCopy.Clear());
var atlasPtr = ImGuiNative.ImFontAtlas_ImFontAtlas();
var atlasPtr = ImGui.ImFontAtlas();
this.Atlas = atlasPtr;
if (this.Atlas.NativePtr is null)
if (this.Atlas.Handle is null)
throw new OutOfMemoryException($"Failed to allocate a new {nameof(ImFontAtlas)}.");
this.Garbage.Add(() => ImGuiNative.ImFontAtlas_destroy(atlasPtr));
this.Garbage.Add(() => this.Atlas.Destroy());
this.IsBuildInProgress = true;
Interlocked.Increment(ref numActiveInstances);
@ -128,7 +126,7 @@ internal sealed partial class FontAtlasFactory
if (this.wraps is null)
throw new ObjectDisposedException(nameof(FontAtlasBuiltData));
var handle = wrap.ImGuiHandle;
var handle = wrap.Handle;
var index = this.ImTextures.IndexOf(x => x.TexID == handle);
if (index == -1)
{
@ -189,7 +187,7 @@ internal sealed partial class FontAtlasFactory
case IRefCountable.RefCountResult.FinalRelease:
#if VeryVerboseLog
Log.Verbose("[{name}] 0x{ptr:X}: Disposing", this.Owner?.Name ?? "<?>", (nint)this.Atlas.NativePtr);
Log.Verbose("[{name}] 0x{ptr:X}: Disposing", this.Owner?.Name ?? "<?>", (nint)this.Atlas.Handle);
#endif
if (this.IsBuildInProgress)
@ -200,7 +198,7 @@ internal sealed partial class FontAtlasFactory
"[{name}] 0x{ptr:X}: Trying to dispose while build is in progress; disposing later.\n" +
"Stack:\n{trace}",
this.Owner?.Name ?? "<?>",
(nint)this.Atlas.NativePtr,
(nint)this.Atlas.Handle,
new StackTrace());
}
@ -310,7 +308,7 @@ internal sealed partial class FontAtlasFactory
throw;
}
this.factory.SceneTask.ContinueWith(
this.factory.BackendTask.ContinueWith(
r =>
{
lock (this.syncRoot)
@ -318,8 +316,8 @@ internal sealed partial class FontAtlasFactory
if (this.disposed)
return;
r.Result.OnNewRenderFrame += this.ImGuiSceneOnNewRenderFrame;
this.disposables.Add(() => r.Result.OnNewRenderFrame -= this.ImGuiSceneOnNewRenderFrame);
r.Result.NewRenderFrame += this.ImGuiSceneOnNewRenderFrame;
this.disposables.Add(() => r.Result.NewRenderFrame -= this.ImGuiSceneOnNewRenderFrame);
}
if (this.AutoRebuildMode == FontAtlasAutoRebuildMode.OnNewFrame)
@ -372,7 +370,7 @@ internal sealed partial class FontAtlasFactory
public Task BuildTask => this.buildTask;
/// <inheritdoc/>
public bool HasBuiltAtlas => !(this.builtData?.Atlas.IsNull() ?? true);
public bool HasBuiltAtlas => !(this.builtData?.Atlas.IsNull ?? true);
/// <inheritdoc/>
public bool IsGlobalScaled { get; }
@ -555,7 +553,7 @@ internal sealed partial class FontAtlasFactory
}
var res = await this.RebuildFontsPrivate(true, scale);
if (res.Atlas.IsNull())
if (res.Atlas.IsNull)
return res;
this.PromoteBuiltData(rebuildIndex, res, nameof(this.BuildFontsAsync));
@ -653,7 +651,7 @@ internal sealed partial class FontAtlasFactory
res.InitialAddSubstance(fhm.NewSubstance(res));
unsafe
{
atlasPtr = (nint)res.Atlas.NativePtr;
atlasPtr = (nint)res.Atlas.Handle;
}
Log.Verbose(
@ -688,7 +686,7 @@ internal sealed partial class FontAtlasFactory
res.InitialAddSubstance(fhm.NewSubstance(res));
unsafe
{
atlasPtr = (nint)res.Atlas.NativePtr;
atlasPtr = (nint)res.Atlas.Handle;
}
toolkit = res.CreateToolkit(this.factory, isAsync);
@ -721,7 +719,7 @@ internal sealed partial class FontAtlasFactory
foreach (var font in toolkit.Fonts)
toolkit.BuildLookupTable(font);
if (this.factory.SceneTask is { IsCompleted: false } sceneTask)
if (this.factory.BackendTask is { IsCompleted: false } backendTask)
{
Log.Verbose(
"[{name}:{functionname}] 0x{ptr:X}: await SceneTask (at {sw}ms)",
@ -729,7 +727,7 @@ internal sealed partial class FontAtlasFactory
nameof(this.RebuildFontsPrivateReal),
atlasPtr,
sw.ElapsedMilliseconds);
await sceneTask.ConfigureAwait(!isAsync);
await backendTask.ConfigureAwait(!isAsync);
}
#if VeryVerboseLog

View file

@ -5,24 +5,20 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Bindings.ImGui;
using Dalamud.Configuration.Internal;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Interface.FontIdentifier;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.ImGuiBackend;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures.Internal;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Storage.Assets;
using Dalamud.Utility;
using ImGuiNET;
using ImGuiScene;
using Lumina.Data.Files;
using TerraFX.Interop.DirectX;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
@ -52,9 +48,9 @@ internal sealed partial class FontAtlasFactory
this.Framework = framework;
this.InterfaceManager = interfaceManager;
this.dalamudAssetManager = dalamudAssetManager;
this.SceneTask = Service<InterfaceManager.InterfaceManagerWithScene>
this.BackendTask = Service<InterfaceManager.InterfaceManagerWithScene>
.GetAsync()
.ContinueWith(r => r.Result.Manager.Scene);
.ContinueWith(r => r.Result.Manager.Backend);
var gffasInfo = Enum.GetValues<GameFontFamilyAndSize>()
.Select(
@ -133,7 +129,7 @@ internal sealed partial class FontAtlasFactory
/// <summary>
/// Gets the service instance of <see cref="InterfaceManager"/>.<br />
/// <see cref="Internal.InterfaceManager.Scene"/> may not yet be available.
/// <see cref="Internal.InterfaceManager.Backend"/> may not yet be available.
/// </summary>
public InterfaceManager InterfaceManager { get; }
@ -143,9 +139,9 @@ internal sealed partial class FontAtlasFactory
public TextureManager TextureManager => Service<TextureManager>.Get();
/// <summary>
/// Gets the async task for <see cref="RawDX11Scene"/> inside <see cref="InterfaceManager"/>.
/// Gets the async task for <see cref="IImGuiBackend"/> inside <see cref="InterfaceManager"/>.
/// </summary>
public Task<RawDX11Scene> SceneTask { get; }
public Task<IImGuiBackend> BackendTask { get; }
/// <summary>
/// Gets the default glyph ranges (glyph ranges of <see cref="GameFontFamilyAndSize.Axis12"/>).

View file

@ -4,14 +4,12 @@ using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
using ImGuiNET;
using Serilog;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
@ -184,7 +182,7 @@ internal abstract class FontHandle : IFontHandle
}
var fontPtr = substance.GetFontPtr(this);
if (fontPtr.IsNull())
if (fontPtr.IsNull)
{
// The font for the requested handle is unavailable. Release the reference and try again.
substance.DataRoot.Release();

View file

@ -1,19 +1,17 @@
using System.Buffers;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive.Disposables;
using Dalamud.Bindings.ImGui;
using Dalamud.Game.Text;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Utility;
using Dalamud.Utility;
using ImGuiNET;
using Lumina.Data.Files;
using Vector4 = System.Numerics.Vector4;
@ -252,7 +250,7 @@ internal class GamePrebakedFontHandle : FontHandle
GameFontStyle style,
ushort[]? glyphRanges = null)
{
if (font.IsNull())
if (font.IsNull)
font = this.CreateTemplateFont(toolkitPreBuild, style.SizePx);
this.attachments.Add((font, style, glyphRanges));
return font;
@ -381,7 +379,10 @@ internal class GamePrebakedFontHandle : FontHandle
var pixels8Array = new byte*[toolkitPostBuild.NewImAtlas.Textures.Size];
var widths = new int[toolkitPostBuild.NewImAtlas.Textures.Size];
for (var i = 0; i < pixels8Array.Length; i++)
toolkitPostBuild.NewImAtlas.GetTexDataAsAlpha8(i, out pixels8Array[i], out widths[i], out _);
{
var width = 0;
toolkitPostBuild.NewImAtlas.GetTexDataAsAlpha8(i, ref pixels8Array[i], ref widths[i], ref width);
}
foreach (var (style, plan) in this.fonts)
{
@ -429,7 +430,7 @@ internal class GamePrebakedFontHandle : FontHandle
var fas = style.Scale(atlasScale).FamilyAndSize;
using var handle = this.handleManager.GameFontTextureProvider.CreateFdtFileView(fas, out var fdt);
ref var fdtFontHeader = ref fdt.FontHeader;
var fontPtr = font.NativePtr;
var fontPtr = font.Handle;
var scale = style.SizePt / fdtFontHeader.Size;
fontPtr->Ascent = fdtFontHeader.Ascent * scale;
@ -513,7 +514,7 @@ internal class GamePrebakedFontHandle : FontHandle
var ranges = this.Ranges[this.FullRangeFont];
foreach (var (font, extraRange) in this.Ranges)
{
if (font.NativePtr != this.FullRangeFont.NativePtr)
if (font.Handle != this.FullRangeFont.Handle)
ranges.Or(extraRange);
}
@ -562,7 +563,7 @@ internal class GamePrebakedFontHandle : FontHandle
public unsafe void PostProcessFullRangeFont(float atlasScale)
{
var round = 1 / atlasScale;
var pfrf = this.FullRangeFont.NativePtr;
var pfrf = this.FullRangeFont.Handle;
ref var frf = ref *pfrf;
frf.FontSize = MathF.Round(frf.FontSize / round) * round;
@ -589,19 +590,18 @@ internal class GamePrebakedFontHandle : FontHandle
continue;
if (!fullRange[leftInt] || !fullRange[rightInt])
continue;
ImGuiNative.ImFont_AddKerningPair(
pfrf,
pfrf->AddKerningPair(
(ushort)leftInt,
(ushort)rightInt,
MathF.Round((k.RightOffset * scale) / round) * round);
}
pfrf->FallbackGlyph = null;
ImGuiNative.ImFont_BuildLookupTable(pfrf);
pfrf->BuildLookupTable();
foreach (var fallbackCharCandidate in FontAtlasFactory.FallbackCodepoints)
{
var glyph = ImGuiNative.ImFont_FindGlyphNoFallback(pfrf, fallbackCharCandidate);
var glyph = pfrf->FindGlyphNoFallback(fallbackCharCandidate);
if ((nint)glyph == IntPtr.Zero)
continue;
frf.FallbackChar = fallbackCharCandidate;
@ -619,7 +619,7 @@ internal class GamePrebakedFontHandle : FontHandle
foreach (var (font, rangeBits) in this.Ranges)
{
if (font.NativePtr == this.FullRangeFont.NativePtr)
if (font.Handle == this.FullRangeFont.Handle)
continue;
var fontScaleMode = toolkitPostBuild.GetFontScaleMode(font);
@ -681,16 +681,16 @@ internal class GamePrebakedFontHandle : FontHandle
}
}
font.NativePtr->FallbackGlyph = null;
font.Handle->FallbackGlyph = null;
font.BuildLookupTable();
foreach (var fallbackCharCandidate in FontAtlasFactory.FallbackCodepoints)
{
var glyph = font.FindGlyphNoFallback(fallbackCharCandidate).NativePtr;
if ((nint)glyph == IntPtr.Zero)
var glyph = font.FindGlyphNoFallback(fallbackCharCandidate);
if (glyph == null)
continue;
ref var frf = ref *font.NativePtr;
ref var frf = ref *font.Handle;
frf.FallbackChar = fallbackCharCandidate;
frf.FallbackGlyph = glyph;
frf.FallbackHotData =
@ -804,8 +804,7 @@ internal class GamePrebakedFontHandle : FontHandle
else
{
ref var rc = ref *(ImGuiHelpers.ImFontAtlasCustomRectReal*)toolkitPostBuild.NewImAtlas
.GetCustomRectByIndex(rectId)
.NativePtr;
.GetCustomRectByIndex(rectId);
var widthAdjustment = this.BaseStyle.CalculateBaseWidthAdjustment(fdtFontHeader, fdtGlyph);
// Glyph is scaled at this point; undo that.

View file

@ -1,9 +1,8 @@
using System.Collections.Generic;
using Dalamud.Bindings.ImGui;
using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
/// <summary>
@ -45,7 +44,7 @@ internal interface IFontHandleSubstance : IDisposable
/// </summary>
/// <param name="toolkitPreBuild">The toolkit.</param>
void OnPreBuild(IFontAtlasBuildToolkitPreBuild toolkitPreBuild);
/// <summary>
/// Called between <see cref="OnPreBuild"/> and <see cref="ImFontAtlasPtr.Build"/> calls.<br />
/// Any further modification to <see cref="IFontAtlasBuildToolkit.Fonts"/> will result in undefined behavior.

View file

@ -1,7 +1,6 @@
using Dalamud.Bindings.ImGui;
using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
/// <summary>

View file

@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility;
using ImGuiNET;
using Microsoft.Extensions.ObjectPool;
using Serilog;
@ -32,10 +31,10 @@ internal sealed class SimplePushedFont : IDisposable
public static SimplePushedFont Rent(List<IDisposable> stack, ImFontPtr fontPtr)
{
var rented = Pool.Get();
Debug.Assert(rented.font.IsNull(), "Rented object must not have its font set");
Debug.Assert(rented.font.IsNull, "Rented object must not have its font set");
rented.stack = stack;
if (fontPtr.IsNotNullAndLoaded())
if (!fontPtr.IsNull && fontPtr.IsLoaded())
{
rented.font = fontPtr;
ImGui.PushFont(fontPtr);
@ -54,9 +53,9 @@ internal sealed class SimplePushedFont : IDisposable
this.stack.RemoveAt(this.stack.Count - 1);
if (!this.font.IsNull())
if (!this.font.IsNull)
{
if (ImGui.GetFont().NativePtr == this.font.NativePtr)
if (ImGui.GetFont().Handle == this.font.Handle)
{
ImGui.PopFont();
}

View file

@ -2,10 +2,9 @@ using System.Buffers.Binary;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility;
using ImGuiNET;
namespace Dalamud.Interface.ManagedFontAtlas.Internals;
/// <summary>
@ -18,7 +17,7 @@ internal static partial class TrueTypeUtils
/// and throws an appropriate exception if it is the case.
/// </summary>
/// <param name="fontConfig">The font config.</param>
public static unsafe void CheckImGuiCompatibleOrThrow(in ImFontConfig fontConfig)
public static unsafe void CheckImGuiCompatibleOrThrow(in ImFontConfigPtr fontConfig)
{
var ranges = fontConfig.GlyphRanges;
var sfnt = AsSfntFile(fontConfig);
@ -35,7 +34,7 @@ internal static partial class TrueTypeUtils
/// <param name="fontConfig">The font config.</param>
/// <returns>The enumerable of pair adjustments. Distance values need to be multiplied by font size in pixels.</returns>
public static IEnumerable<(char Left, char Right, float Distance)> ExtractHorizontalPairAdjustments(
ImFontConfig fontConfig)
ImFontConfigPtr fontConfig)
{
float multiplier;
Dictionary<ushort, char[]> glyphToCodepoints;
@ -107,7 +106,7 @@ internal static partial class TrueTypeUtils
}
}
private static unsafe SfntFile AsSfntFile(in ImFontConfig fontConfig)
private static unsafe SfntFile AsSfntFile(in ImFontConfigPtr fontConfig)
{
var memory = new PointerSpan<byte>((byte*)fontConfig.FontData, fontConfig.FontDataSize);
if (memory.Length < 4)