Implement FontChooserDialog (#1637)

* Implement FontChooserDialog

* Minor fixes

* Fixes 2

* Add Reset default font button

* Add failsafe

* reduce uninteresting exception message

* Add remarks to use AttachExtraGlyphsForDalamudLanguage

* Support advanced font configuration options

* fixes

* Shift ui elements

* more fixes

* Add To(Localized)String for IFontSpec

* Untie GlobalFontScale from default font size

* Layout fixes

* Make UiBuilder.DefaultFontSize point to user configured value

* Update example for NewDelegateFontHandle

* Font interfaces: write notes on not intended for plugins to implement

* Update default gamma to 1.7 to match closer to prev behavior (1.4**2)

* Fix console window layout
This commit is contained in:
srkizer 2024-02-14 05:09:46 +09:00 committed by GitHub
parent 3b3823d4e6
commit 34daa73612
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 2478 additions and 81 deletions

View file

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Text.Unicode;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.FontIdentifier;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility;
@ -42,6 +43,7 @@ internal sealed partial class FontAtlasFactory
private readonly GamePrebakedFontHandle.HandleSubstance gameFontHandleSubstance;
private readonly FontAtlasFactory factory;
private readonly FontAtlasBuiltData data;
private readonly List<Action> registeredPostBuildActions = new();
/// <summary>
/// Initializes a new instance of the <see cref="BuildToolkit"/> class.
@ -162,6 +164,9 @@ internal sealed partial class FontAtlasFactory
/// <inheritdoc/>
public int StoreTexture(IDalamudTextureWrap textureWrap, bool disposeOnError) =>
this.data.AddNewTexture(textureWrap, disposeOnError);
/// <inheritdoc/>
public void RegisterPostBuild(Action action) => this.registeredPostBuildActions.Add(action);
/// <inheritdoc/>
public unsafe ImFontPtr AddFontFromImGuiHeapAllocatedMemory(
@ -314,18 +319,32 @@ internal sealed partial class FontAtlasFactory
/// <inheritdoc/>
public ImFontPtr AddDalamudDefaultFont(float sizePx, ushort[]? glyphRanges)
{
ImFontPtr font;
ImFontPtr font = default;
glyphRanges ??= this.factory.DefaultGlyphRanges;
if (this.factory.UseAxis)
var dfid = this.factory.DefaultFontSpec;
if (sizePx < 0f)
sizePx *= -dfid.SizePx;
if (dfid is SingleFontSpec sfs)
{
font = this.AddGameGlyphs(new(GameFontFamily.Axis, sizePx), glyphRanges, default);
if (sfs.FontId is DalamudDefaultFontAndFamilyId)
{
// invalid; calling sfs.AddToBuildToolkit calls this function, causing infinite recursion
}
else
{
sfs = sfs with { SizePx = sizePx };
font = sfs.AddToBuildToolkit(this);
if (sfs.FontId is not GameFontAndFamilyId { GameFontFamily: GameFontFamily.Axis })
this.AddGameSymbol(new() { SizePx = sizePx, MergeFont = font });
}
}
else
if (font.IsNull())
{
font = this.AddDalamudAssetFont(
DalamudAsset.NotoSansJpMedium,
new() { SizePx = sizePx, GlyphRanges = glyphRanges });
this.AddGameSymbol(new() { SizePx = sizePx, MergeFont = font });
// fall back to AXIS fonts
font = this.AddGameGlyphs(new(GameFontFamily.Axis, sizePx), glyphRanges, default);
}
this.AttachExtraGlyphsForDalamudLanguage(new() { SizePx = sizePx, MergeFont = font });
@ -531,6 +550,13 @@ internal sealed partial class FontAtlasFactory
substance.OnPostBuild(this);
}
public void PostBuildCallbacks()
{
foreach (var ac in this.registeredPostBuildActions)
ac.InvokeSafely();
this.registeredPostBuildActions.Clear();
}
public unsafe void UploadTextures()
{
var buf = Array.Empty<byte>();

View file

@ -658,7 +658,7 @@ internal sealed partial class FontAtlasFactory
toolkit = res.CreateToolkit(this.factory, isAsync);
// PreBuildSubstances deals with toolkit.Add... function family. Do this first.
var defaultFont = toolkit.AddDalamudDefaultFont(InterfaceManager.DefaultFontSizePx, null);
var defaultFont = toolkit.AddDalamudDefaultFont(-1, null);
this.BuildStepChange?.Invoke(toolkit);
toolkit.PreBuildSubstances();
@ -679,6 +679,7 @@ internal sealed partial class FontAtlasFactory
toolkit.PostBuild();
toolkit.PostBuildSubstances();
toolkit.PostBuildCallbacks();
this.BuildStepChange?.Invoke(toolkit);
foreach (var font in toolkit.Fonts)

View file

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Dalamud.Configuration.Internal;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Interface.FontIdentifier;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Internal;
using Dalamud.Storage.Assets;
@ -108,14 +109,29 @@ internal sealed partial class FontAtlasFactory
}
/// <summary>
/// Gets or sets a value indicating whether to override configuration for UseAxis.
/// Gets or sets a value indicating whether to override configuration for <see cref="DefaultFontSpec"/>.
/// </summary>
public bool? UseAxisOverride { get; set; } = null;
public IFontSpec? DefaultFontSpecOverride { get; set; } = null;
/// <summary>
/// Gets a value indicating whether to use AXIS fonts.
/// Gets the default font ID.
/// </summary>
public bool UseAxis => this.UseAxisOverride ?? Service<DalamudConfiguration>.Get().UseAxisFontsFromGame;
public IFontSpec DefaultFontSpec =>
this.DefaultFontSpecOverride
?? Service<DalamudConfiguration>.Get().DefaultFontSpec
#pragma warning disable CS0618 // Type or member is obsolete
?? (Service<DalamudConfiguration>.Get().UseAxisFontsFromGame
#pragma warning restore CS0618 // Type or member is obsolete
? new()
{
FontId = new GameFontAndFamilyId(GameFontFamily.Axis),
SizePx = InterfaceManager.DefaultFontSizePx,
}
: new SingleFontSpec
{
FontId = new DalamudAssetFontAndFamilyId(DalamudAsset.NotoSansJpMedium),
SizePx = InterfaceManager.DefaultFontSizePx + 1,
});
/// <summary>
/// Gets the service instance of <see cref="Framework"/>.