mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Fix AddDalamudDefaultFont on not using lodestone symbol fonts file
This commit is contained in:
parent
f8e6df1172
commit
701d006db8
4 changed files with 46 additions and 20 deletions
|
|
@ -120,7 +120,9 @@ public interface IFontAtlasBuildToolkitPreBuild : IFontAtlasBuildToolkit
|
|||
/// <summary>
|
||||
/// Adds the default font known to the current font atlas.<br />
|
||||
/// <br />
|
||||
/// Default font includes <see cref="AddFontAwesomeIconFont"/> and <see cref="AddExtraGlyphsForDalamudLanguage"/>.
|
||||
/// Includes <see cref="AddFontAwesomeIconFont"/> and <see cref="AddExtraGlyphsForDalamudLanguage"/>.<br />
|
||||
/// As this involves adding multiple fonts, calling this function will set <see cref="IFontAtlasBuildToolkit.Font"/>
|
||||
/// as the return value of this function, if it was empty before.
|
||||
/// </summary>
|
||||
/// <param name="sizePx">Font size in pixels.</param>
|
||||
/// <param name="glyphRanges">The glyph ranges. Use <see cref="FontAtlasBuildToolkitUtilities"/>.ToGlyphRange to build.</param>
|
||||
|
|
@ -132,7 +134,8 @@ public interface IFontAtlasBuildToolkitPreBuild : IFontAtlasBuildToolkit
|
|||
/// <br />
|
||||
/// 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 <paramref name="fontConfig"/>
|
||||
/// will be ignored but <see cref="SafeFontConfig.SizePx"/> and <see cref="SafeFontConfig.MergeFont"/>.
|
||||
/// will be ignored but <see cref="SafeFontConfig.SizePx"/>, <see cref="SafeFontConfig.MergeFont"/>,
|
||||
/// and <see cref="SafeFontConfig.GlyphRanges"/>.
|
||||
/// </summary>
|
||||
/// <param name="asset">The font type.</param>
|
||||
/// <param name="fontConfig">The font config.</param>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<GameFontStyle, ImFontPtr> fonts = new();
|
||||
private readonly Dictionary<GameFontStyle, Exception?> buildExceptions = new();
|
||||
|
||||
private readonly Dictionary<GameFontStyle, ImFontPtr> fontsSymbolsOnly = new();
|
||||
private readonly Dictionary<ImFontPtr, HashSet<ImFontPtr>> symbolsCopyTargets = new();
|
||||
private readonly Dictionary<ImFontPtr, List<(ImFontPtr Font, ushort[]? Ranges)>> fontCopyTargets = new();
|
||||
|
||||
private readonly HashSet<ImFontPtr> templatedFonts = new();
|
||||
private readonly Dictionary<ImFontPtr, List<(char From, char To)>> lateBuildRanges = new();
|
||||
|
|
@ -250,23 +248,24 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal
|
|||
/// <param name="toolkitPreBuild">The toolkitPostBuild.</param>
|
||||
/// <param name="font">The font to attach to.</param>
|
||||
/// <param name="sizePx">The font size in pixels.</param>
|
||||
/// <param name="glyphRanges">The intended glyph ranges.</param>
|
||||
/// <returns><paramref name="font"/> if it is not empty; otherwise a new font.</returns>
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue