using Dalamud.Bindings.ImGui; using Dalamud.Utility; namespace Dalamud.Interface.ManagedFontAtlas.Internals; /// /// The implementation for . /// internal class LockedImFont : ILockedImFont { private IRefCountable? owner; /// /// Initializes a new instance of the class. /// Ownership of reference of is transferred. /// /// The contained font. /// The owner. /// The rented instance of . internal LockedImFont(ImFontPtr font, IRefCountable owner) { this.ImFont = font; this.owner = owner; } /// /// Finalizes an instance of the class. /// ~LockedImFont() => this.FreeOwner(); /// public ImFontPtr ImFont { get; private set; } /// public ILockedImFont NewRef() { if (this.owner is null) throw new ObjectDisposedException(nameof(LockedImFont)); var newRef = new LockedImFont(this.ImFont, this.owner); this.owner.AddRef(); return newRef; } /// public void Dispose() { this.FreeOwner(); GC.SuppressFinalize(this); } private void FreeOwner() { if (this.owner is null) return; this.owner.Release(); this.owner = null; this.ImFont = default; } }