font scaling tweaks

pull/52/head
cosmonaut 2023-12-07 22:54:58 -08:00
parent 26df8fa77c
commit 420f5caee9
3 changed files with 12 additions and 9 deletions

@ -1 +1 @@
Subproject commit 0ffacd6aec80d94cf45a871bd50c9a9321f4ec0d
Subproject commit 82093d2b0d4ee8510820213cbcd248418528a88c

View File

@ -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,

View File

@ -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,