mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
Add FontAwesome fixed width (#1737)
* Add FA-FW * remove braces (ask of kizer) * reuse iconfont glyphs * use FAFS for initial font --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
parent
b8802f0609
commit
e97d95dba8
4 changed files with 87 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
|
@ -166,7 +166,7 @@ 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);
|
||||
|
||||
|
|
@ -391,12 +391,10 @@ internal sealed partial class FontAtlasFactory
|
|||
});
|
||||
|
||||
case DalamudAsset.LodestoneGameSymbol when !this.factory.HasGameSymbolsFontFile:
|
||||
{
|
||||
return this.AddGameGlyphs(
|
||||
new(GameFontFamily.Axis, fontConfig.SizePx),
|
||||
fontConfig.GlyphRanges,
|
||||
fontConfig.MergeFont);
|
||||
}
|
||||
|
||||
default:
|
||||
return this.factory.AddFont(
|
||||
|
|
@ -858,5 +856,30 @@ internal sealed partial class FontAtlasFactory
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void FitRatio(ImFontPtr font, bool rebuildLookupTable = true)
|
||||
{
|
||||
var nsize = font.FontSize;
|
||||
var glyphs = font.GlyphsWrapped();
|
||||
foreach (ref var glyph in glyphs.DataSpan)
|
||||
{
|
||||
var ratio = 1f;
|
||||
if (glyph.X1 - glyph.X0 > nsize)
|
||||
ratio = Math.Max(ratio, (glyph.X1 - glyph.X0) / nsize);
|
||||
if (glyph.Y1 - glyph.Y0 > nsize)
|
||||
ratio = Math.Max(ratio, (glyph.Y1 - glyph.Y0) / nsize);
|
||||
var w = MathF.Round((glyph.X1 - glyph.X0) / ratio, MidpointRounding.ToZero);
|
||||
var h = MathF.Round((glyph.Y1 - glyph.Y0) / ratio, MidpointRounding.AwayFromZero);
|
||||
glyph.X0 = MathF.Round((nsize - w) / 2f, MidpointRounding.ToZero);
|
||||
glyph.Y0 = MathF.Round((nsize - h) / 2f, MidpointRounding.AwayFromZero);
|
||||
glyph.X1 = glyph.X0 + w;
|
||||
glyph.Y1 = glyph.Y0 + h;
|
||||
glyph.AdvanceX = nsize;
|
||||
}
|
||||
|
||||
if (rebuildLookupTable)
|
||||
this.BuildLookupTable(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue