diff --git a/Dalamud/Interface/ManagedFontAtlas/IFontAtlasBuildToolkitPreBuild.cs b/Dalamud/Interface/ManagedFontAtlas/IFontAtlasBuildToolkitPreBuild.cs index e8f11aec3..dbe8626e9 100644 --- a/Dalamud/Interface/ManagedFontAtlas/IFontAtlasBuildToolkitPreBuild.cs +++ b/Dalamud/Interface/ManagedFontAtlas/IFontAtlasBuildToolkitPreBuild.cs @@ -120,7 +120,9 @@ public interface IFontAtlasBuildToolkitPreBuild : IFontAtlasBuildToolkit /// /// Adds the default font known to the current font atlas.
///
- /// Default font includes and . + /// Includes and .
+ /// As this involves adding multiple fonts, calling this function will set + /// as the return value of this function, if it was empty before. ///
/// Font size in pixels. /// The glyph ranges. Use .ToGlyphRange to build. @@ -132,7 +134,8 @@ public interface IFontAtlasBuildToolkitPreBuild : IFontAtlasBuildToolkit ///
/// Note: if game symbols font file is requested but is unavailable, /// then it will take the glyphs from game's built-in fonts, and everything in - /// will be ignored but and . + /// will be ignored but , , + /// and . /// /// The font type. /// The font config. diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs index bc48ddcc1..142bd73da 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs @@ -211,7 +211,8 @@ internal class DelegateFontHandle : IFontHandle.IInternal { Log.Warning( "[{name}:Substance] {n} fonts added from {delegate} PreBuild call; " + - "did you mean to use {sfd}.{sfdprop} or {ifcp}.{ifcpprop}?", + "Using the most recently added font. " + + "Did you mean to use {sfd}.{sfdprop} or {ifcp}.{ifcpprop}?", this.Manager.Name, fontsVector.Length - fontCountPrevious, nameof(FontAtlasBuildStepDelegate), @@ -262,7 +263,7 @@ internal class DelegateFontHandle : IFontHandle.IInternal { var distinct = fontsVector - .DistinctBy(x => (nint)x.NativePtr) // Remove duplicates + .DistinctBy(x => (nint)x.NativePtr) // Remove duplicates .Where(x => x.ValidateUnsafe() is null) // Remove invalid entries without freeing them .ToArray(); diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs index 9ebf20fc7..8e115c126 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/FontAtlasFactory.BuildToolkit.cs @@ -291,6 +291,8 @@ internal sealed partial class FontAtlasFactory var font = this.AddDalamudAssetFont(DalamudAsset.NotoSansJpMedium, fontConfig); this.AddExtraGlyphsForDalamudLanguage(fontConfig with { MergeFont = font }); this.AddGameSymbol(fontConfig with { MergeFont = font }); + if (this.Font.IsNull()) + this.Font = font; return font; } @@ -316,7 +318,8 @@ internal sealed partial class FontAtlasFactory return this.gameFontHandleSubstance.AttachGameSymbols( this, fontConfig.MergeFont, - fontConfig.SizePx); + fontConfig.SizePx, + fontConfig.GlyphRanges); default: return this.factory.AddFont( diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs index 012613a38..37266f39b 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs @@ -214,9 +214,7 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal // Owned by this class, but ImFontPtr values still do not belong to this. private readonly Dictionary fonts = new(); private readonly Dictionary buildExceptions = new(); - - private readonly Dictionary fontsSymbolsOnly = new(); - private readonly Dictionary> symbolsCopyTargets = new(); + private readonly Dictionary> fontCopyTargets = new(); private readonly HashSet templatedFonts = new(); private readonly Dictionary> lateBuildRanges = new(); @@ -250,23 +248,24 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal /// The toolkitPostBuild. /// The font to attach to. /// The font size in pixels. + /// The intended glyph ranges. /// if it is not empty; otherwise a new font. - public ImFontPtr AttachGameSymbols(IFontAtlasBuildToolkitPreBuild toolkitPreBuild, ImFontPtr font, float sizePx) + public ImFontPtr AttachGameSymbols( + IFontAtlasBuildToolkitPreBuild toolkitPreBuild, + ImFontPtr font, + float sizePx, + ushort[]? glyphRanges) { var style = new GameFontStyle(GameFontFamily.Axis, sizePx); - if (!this.fontsSymbolsOnly.TryGetValue(style, out var symbolFont)) - { - symbolFont = this.CreateFontPrivate(style, toolkitPreBuild, ' ', '\uFFFE', true); - this.fontsSymbolsOnly.Add(style, symbolFont); - } + var referenceFont = this.GetOrCreateFont(style, toolkitPreBuild); if (font.IsNull()) font = this.CreateTemplateFont(style, toolkitPreBuild); - if (!this.symbolsCopyTargets.TryGetValue(symbolFont, out var set)) - this.symbolsCopyTargets[symbolFont] = set = new(); + if (!this.fontCopyTargets.TryGetValue(referenceFont, out var copyTargets)) + this.fontCopyTargets[referenceFont] = copyTargets = new(); - set.Add(font); + copyTargets.Add((font, glyphRanges)); return font; } @@ -342,7 +341,7 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal for (var i = 0; i < pixels8Array.Length; i++) toolkitPostBuild.NewImAtlas.GetTexDataAsAlpha8(i, out pixels8Array[i], out widths[i], out heights[i]); - foreach (var (style, font) in this.fonts.Concat(this.fontsSymbolsOnly)) + foreach (var (style, font) in this.fonts) { try { @@ -585,10 +584,30 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal } } - foreach (var (source, targets) in this.symbolsCopyTargets) + foreach (var (source, targets) in this.fontCopyTargets) { foreach (var target in targets) - ImGuiHelpers.CopyGlyphsAcrossFonts(source, target, true, true, SeIconCharMin, SeIconCharMax); + { + if (target.Ranges is null) + { + ImGuiHelpers.CopyGlyphsAcrossFonts(source, target.Font, missingOnly: true); + } + else + { + for (var i = 0; i < target.Ranges.Length; i += 2) + { + if (target.Ranges[i] == 0) + break; + ImGuiHelpers.CopyGlyphsAcrossFonts( + source, + target.Font, + true, + true, + target.Ranges[i], + target.Ranges[i + 1]); + } + } + } } }