using System.Collections.Generic;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.ManagedFontAtlas;
using Newtonsoft.Json;
using TerraFX.Interop.DirectX;
namespace Dalamud.Interface.FontIdentifier;
///
/// Represents a font from the game.
///
public sealed class GameFontAndFamilyId : IFontId, IFontFamilyId
{
///
/// Initializes a new instance of the class.
///
/// The game font family.
public GameFontAndFamilyId(GameFontFamily family) => this.GameFontFamily = family;
///
/// Gets the game font family.
///
[JsonProperty]
public GameFontFamily GameFontFamily { get; init; }
///
[JsonIgnore]
public string EnglishName => $"Game: {Enum.GetName(this.GameFontFamily) ?? throw new NotSupportedException()}";
///
[JsonIgnore]
public IReadOnlyDictionary? LocaleNames => null;
///
[JsonIgnore]
public IFontFamilyId Family => this;
///
[JsonIgnore]
public int Weight => (int)DWRITE_FONT_WEIGHT.DWRITE_FONT_WEIGHT_NORMAL;
///
[JsonIgnore]
public int Stretch => (int)DWRITE_FONT_STRETCH.DWRITE_FONT_STRETCH_NORMAL;
///
[JsonIgnore]
public int Style => (int)DWRITE_FONT_STYLE.DWRITE_FONT_STYLE_NORMAL;
///
[JsonIgnore]
public IReadOnlyList Fonts => new List { this }.AsReadOnly();
public static bool operator ==(GameFontAndFamilyId? left, GameFontAndFamilyId? right) => Equals(left, right);
public static bool operator !=(GameFontAndFamilyId? left, GameFontAndFamilyId? right) => !Equals(left, right);
///
public override bool Equals(object? obj) =>
ReferenceEquals(this, obj) || (obj is GameFontAndFamilyId other && this.Equals(other));
///
public override int GetHashCode() => (int)this.GameFontFamily;
///
public int FindBestMatch(int weight, int stretch, int style) => 0;
///
public override string ToString() => $"{nameof(GameFontAndFamilyId)}:{this.GameFontFamily}";
///
public ImFontPtr AddToBuildToolkit(IFontAtlasBuildToolkitPreBuild tk, in SafeFontConfig config) =>
tk.AddGameGlyphs(new(this.GameFontFamily, config.SizePx), config.GlyphRanges, config.MergeFont);
private bool Equals(GameFontAndFamilyId other) => this.GameFontFamily == other.GameFontFamily;
}