mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 05:52:11 +00:00
Added the possibility for an optimization step in the IL2CPU MSBuild task. Currently commented out, but should work fine with a few modifications to the optimizer. Moved classes that are dependent on Cosmos from the Orvid.Graphics, into the Orvid.Graphics.Cosmos assembly. Re-factored the font mechanism, added partially working .fnt Font support. Added a Rectangle class, and a Vec2d class, which is the same as Vec2, except with doubles for the X and Y values. Made a small aesthetic improvement to the output of the File2ByteArray Converter.
90 lines
2 KiB
C#
90 lines
2 KiB
C#
using System;
|
|
|
|
namespace Orvid.Graphics.FontSupport
|
|
{
|
|
public abstract class FontMetrics
|
|
{
|
|
protected Font font;
|
|
|
|
protected FontMetrics(Font font)
|
|
{
|
|
this.font = font;
|
|
}
|
|
|
|
public Font GetFont()
|
|
{
|
|
return font;
|
|
}
|
|
|
|
public virtual int GetLeading()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public virtual int GetAscent()
|
|
{
|
|
return (int)font.Size;
|
|
}
|
|
|
|
public virtual int GetDescent()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public virtual int GetHeight()
|
|
{
|
|
return GetLeading() + GetAscent() + GetDescent();
|
|
}
|
|
|
|
public virtual int GetMaxAscent()
|
|
{
|
|
return GetAscent();
|
|
}
|
|
|
|
public virtual int GetMaxDescent()
|
|
{
|
|
return GetDescent();
|
|
}
|
|
|
|
public virtual int GetMaxAdvance()
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
|
|
public virtual int CharWidth(char ch)
|
|
{
|
|
if (ch < 256)
|
|
{
|
|
return GetWidths()[ch];
|
|
}
|
|
char[] data = { ch };
|
|
return CharsWidth(data, 0, 1);
|
|
}
|
|
|
|
public int StringWidth(String str)
|
|
{
|
|
int len = str.Length;
|
|
char[] data = new char[len];
|
|
Array.Copy(str.ToCharArray(), 0, data, 0,len);
|
|
return CharsWidth(data, 0, len);
|
|
}
|
|
|
|
public abstract int[] CharsWidths(char[] chars, int start, int len);
|
|
|
|
public virtual int CharsWidth(char[] data, int off, int len)
|
|
{
|
|
return StringWidth(new String(data, off, len));
|
|
}
|
|
|
|
public virtual int[] GetWidths()
|
|
{
|
|
int[] widths = new int[256];
|
|
for (char ch = (char)0; ch < 256; ch++)
|
|
{
|
|
widths[ch] = CharWidth(ch);
|
|
}
|
|
return widths;
|
|
}
|
|
}
|
|
}
|