mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-14 11:57:42 +01:00
Add SetFontScaleMode(ImFontPtr, FontScaleMode) (#1666)
* Add SetFontScaleMode(ImFontPtr, FontScaleMode) `IgnoreGlobalScale` was advertised as "excludes the given font from global scaling", but the intent I had in mind was "excludes the given font from being scaled in any manner". As the latter functionality is needed, obsoleted `IgnoreGlobalScale` and added `SetFontScaleMode`. * Make it correct * Name consistency
This commit is contained in:
parent
7dc99c9307
commit
2d8b71c647
9 changed files with 166 additions and 66 deletions
|
|
@ -31,6 +31,8 @@ public interface IFontSpec
|
|||
/// <param name="atlas">The atlas to bind this font handle to.</param>
|
||||
/// <param name="callback">Optional callback to be called after creating the font handle.</param>
|
||||
/// <returns>The new font handle.</returns>
|
||||
/// <remarks><see cref="IFontAtlasBuildToolkit.Font"/> will be set when <paramref name="callback"/> is invoked.
|
||||
/// </remarks>
|
||||
IFontHandle CreateFontHandle(IFontAtlas atlas, FontAtlasBuildStepDelegate? callback = null);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -109,7 +109,9 @@ public record SingleFontSpec : IFontSpec
|
|||
tk.RegisterPostBuild(
|
||||
() =>
|
||||
{
|
||||
var roundUnit = tk.IsGlobalScaleIgnored(font) ? 1 : 1 / tk.Scale;
|
||||
// Multiplication by scale will be done with global scale, outside of this handling.
|
||||
var scale = tk.GetFontScaleMode(font) == FontScaleMode.UndoGlobalScale ? 1 / tk.Scale : 1;
|
||||
var roundUnit = tk.GetFontScaleMode(font) == FontScaleMode.SkipHandling ? 1 : 1 / tk.Scale;
|
||||
var newAscent = MathF.Round((font.Ascent * this.LineHeight) / roundUnit) * roundUnit;
|
||||
var newFontSize = MathF.Round((font.FontSize * this.LineHeight) / roundUnit) * roundUnit;
|
||||
var shiftDown = MathF.Round((newFontSize - font.FontSize) / 2f / roundUnit) * roundUnit;
|
||||
|
|
@ -129,13 +131,10 @@ public record SingleFontSpec : IFontSpec
|
|||
}
|
||||
}
|
||||
|
||||
// `/ roundUnit` = `* scale`
|
||||
var dax = MathF.Round(this.LetterSpacing / roundUnit / roundUnit) * roundUnit;
|
||||
var dxy0 = this.GlyphOffset / roundUnit;
|
||||
|
||||
var dax = MathF.Round((this.LetterSpacing * scale) / roundUnit) * roundUnit;
|
||||
var dxy0 = this.GlyphOffset * scale;
|
||||
dxy0 /= roundUnit;
|
||||
dxy0.X = MathF.Round(dxy0.X);
|
||||
dxy0.Y = MathF.Round(dxy0.Y);
|
||||
dxy0 = new(MathF.Round(dxy0.X), MathF.Round(dxy0.Y));
|
||||
dxy0 *= roundUnit;
|
||||
|
||||
dxy0.Y += shiftDown;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue