From 420f5caee9adc01822c53c444324776968072ebd Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 7 Dec 2023 22:54:58 -0800 Subject: [PATCH] font scaling tweaks --- lib/WellspringCS | 2 +- src/Graphics/Font/Font.cs | 15 ++++++++------- src/Graphics/Font/TextBatch.cs | 4 +++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/WellspringCS b/lib/WellspringCS index 0ffacd6..82093d2 160000 --- a/lib/WellspringCS +++ b/lib/WellspringCS @@ -1 +1 @@ -Subproject commit 0ffacd6aec80d94cf45a871bd50c9a9321f4ec0d +Subproject commit 82093d2b0d4ee8510820213cbcd248418528a88c diff --git a/src/Graphics/Font/Font.cs b/src/Graphics/Font/Font.cs index 024b3df..eafe6d2 100644 --- a/src/Graphics/Font/Font.cs +++ b/src/Graphics/Font/Font.cs @@ -8,6 +8,7 @@ namespace MoonWorks.Graphics.Font public unsafe class Font : IDisposable { public Texture Texture { get; } + public float PixelsPerEm { get; } internal IntPtr Handle { get; } @@ -37,7 +38,8 @@ namespace MoonWorks.Graphics.Font (IntPtr) fontFileByteBuffer, (uint) fontFileByteSpan.Length, (IntPtr) atlasFileByteBuffer, - (uint) atlasFileByteSpan.Length + (uint) atlasFileByteSpan.Length, + out float pixelsPerEm ); var texture = Texture.FromImageFile(graphicsDevice, commandBuffer, Path.ChangeExtension(fontPath, ".png")); @@ -45,13 +47,14 @@ namespace MoonWorks.Graphics.Font NativeMemory.Free(fontFileByteBuffer); NativeMemory.Free(atlasFileByteBuffer); - return new Font(handle, texture); + return new Font(handle, texture, pixelsPerEm); } - private Font(IntPtr handle, Texture texture) + private Font(IntPtr handle, Texture texture, float pixelsPerEm) { Handle = handle; Texture = texture; + PixelsPerEm = pixelsPerEm; StringBytesLength = 32; StringBytes = (byte*) NativeMemory.Alloc((nuint) StringBytesLength); @@ -59,8 +62,7 @@ namespace MoonWorks.Graphics.Font public unsafe bool TextBounds( string text, - float x, - float y, + int pixelSize, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, out Wellspring.Rectangle rectangle @@ -78,8 +80,7 @@ namespace MoonWorks.Graphics.Font var result = Wellspring.Wellspring_TextBounds( Handle, - x, - y, + pixelSize, (Wellspring.HorizontalAlignment) horizontalAlignment, (Wellspring.VerticalAlignment) verticalAlignment, (IntPtr) StringBytes, diff --git a/src/Graphics/Font/TextBatch.cs b/src/Graphics/Font/TextBatch.cs index c043909..d9abf6a 100644 --- a/src/Graphics/Font/TextBatch.cs +++ b/src/Graphics/Font/TextBatch.cs @@ -17,7 +17,7 @@ namespace MoonWorks.Graphics.Font public Buffer IndexBuffer { get; protected set; } = null; public uint PrimitiveCount { get; protected set; } - private Font CurrentFont; + public Font CurrentFont { get; private set; } private byte* StringBytes; private int StringBytesLength; @@ -47,6 +47,7 @@ namespace MoonWorks.Graphics.Font string text, float x, float y, + int pixelSize, float depth, Color color, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, @@ -67,6 +68,7 @@ namespace MoonWorks.Graphics.Font Handle, x, y, + pixelSize, depth, new Wellspring.Color { R = color.R, G = color.G, B = color.B, A = color.A }, (Wellspring.HorizontalAlignment) horizontalAlignment,