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 unsafe class Font : IDisposable
{ {
public Texture Texture { get; } public Texture Texture { get; }
public float PixelsPerEm { get; }
internal IntPtr Handle { get; } internal IntPtr Handle { get; }
@ -37,7 +38,8 @@ namespace MoonWorks.Graphics.Font
(IntPtr) fontFileByteBuffer, (IntPtr) fontFileByteBuffer,
(uint) fontFileByteSpan.Length, (uint) fontFileByteSpan.Length,
(IntPtr) atlasFileByteBuffer, (IntPtr) atlasFileByteBuffer,
(uint) atlasFileByteSpan.Length (uint) atlasFileByteSpan.Length,
out float pixelsPerEm
); );
var texture = Texture.FromImageFile(graphicsDevice, commandBuffer, Path.ChangeExtension(fontPath, ".png")); var texture = Texture.FromImageFile(graphicsDevice, commandBuffer, Path.ChangeExtension(fontPath, ".png"));
@ -45,13 +47,14 @@ namespace MoonWorks.Graphics.Font
NativeMemory.Free(fontFileByteBuffer); NativeMemory.Free(fontFileByteBuffer);
NativeMemory.Free(atlasFileByteBuffer); 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; Handle = handle;
Texture = texture; Texture = texture;
PixelsPerEm = pixelsPerEm;
StringBytesLength = 32; StringBytesLength = 32;
StringBytes = (byte*) NativeMemory.Alloc((nuint) StringBytesLength); StringBytes = (byte*) NativeMemory.Alloc((nuint) StringBytesLength);
@ -59,8 +62,7 @@ namespace MoonWorks.Graphics.Font
public unsafe bool TextBounds( public unsafe bool TextBounds(
string text, string text,
float x, int pixelSize,
float y,
HorizontalAlignment horizontalAlignment, HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment, VerticalAlignment verticalAlignment,
out Wellspring.Rectangle rectangle out Wellspring.Rectangle rectangle
@ -78,8 +80,7 @@ namespace MoonWorks.Graphics.Font
var result = Wellspring.Wellspring_TextBounds( var result = Wellspring.Wellspring_TextBounds(
Handle, Handle,
x, pixelSize,
y,
(Wellspring.HorizontalAlignment) horizontalAlignment, (Wellspring.HorizontalAlignment) horizontalAlignment,
(Wellspring.VerticalAlignment) verticalAlignment, (Wellspring.VerticalAlignment) verticalAlignment,
(IntPtr) StringBytes, (IntPtr) StringBytes,

View File

@ -17,7 +17,7 @@ namespace MoonWorks.Graphics.Font
public Buffer IndexBuffer { get; protected set; } = null; public Buffer IndexBuffer { get; protected set; } = null;
public uint PrimitiveCount { get; protected set; } public uint PrimitiveCount { get; protected set; }
private Font CurrentFont; public Font CurrentFont { get; private set; }
private byte* StringBytes; private byte* StringBytes;
private int StringBytesLength; private int StringBytesLength;
@ -47,6 +47,7 @@ namespace MoonWorks.Graphics.Font
string text, string text,
float x, float x,
float y, float y,
int pixelSize,
float depth, float depth,
Color color, Color color,
HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left,
@ -67,6 +68,7 @@ namespace MoonWorks.Graphics.Font
Handle, Handle,
x, x,
y, y,
pixelSize,
depth, depth,
new Wellspring.Color { R = color.R, G = color.G, B = color.B, A = color.A }, new Wellspring.Color { R = color.R, G = color.G, B = color.B, A = color.A },
(Wellspring.HorizontalAlignment) horizontalAlignment, (Wellspring.HorizontalAlignment) horizontalAlignment,