Make GDI backend draw text consistently with default.png backend.

This commit is contained in:
UnknownShadow200 2016-04-18 16:49:53 +10:00
parent fe746d58de
commit 790e1f783a
8 changed files with 42 additions and 29 deletions

View File

@ -66,6 +66,10 @@ namespace ClassicalSharp {
return Size.Ceiling( total );
}
int PtToPx( int point ) {
return (int)Math.Ceiling( (float)point / 72 * 96 ); // TODO: not sure if even right, non 96 dpi?
}
public override Size MeasureBitmappedSize( ref DrawTextArgs args ) {
return MeasureBitmappedSizeImpl( ref args );
}

View File

@ -66,7 +66,7 @@ namespace ClassicalSharp {
int xMul = args.Font.Style == FontStyle.Italic ? 1 : 0;
int runCount = 0, lastY = -1;
string text = args.Text;
float point = args.Font.Size;
int point = Utils.Floor( args.Font.Size );
byte* coordsPtr = stackalloc byte[256];
for( int i = 0; i < text.Length; i++ ) {
@ -100,23 +100,25 @@ namespace ClassicalSharp {
}
void DrawRun( FastBitmap dst, int x, int y, int xMul, string text,
int runCount, byte* coords, float point, FastColour col ) {
int runCount, byte* coords, int point, FastColour col ) {
if( runCount == 0 ) return;
int srcY = (coords[0] >> 4) * boxSize;
int srcHeight = boxSize, dstHeight = PtToPx( point, srcHeight );
int textHeight = AdjTextSize( point ), cellHeight = CellSize( textHeight );
int padding = (cellHeight - textHeight) / 2;
int startX = x;
ushort* dstWidths = stackalloc ushort[runCount];
for( int i = 0; i < runCount; i++ )
dstWidths[i] = (ushort)PtToPx( point, widths[coords[i]] );
for( int yy = 0; yy < dstHeight; yy++ ) {
int fontY = srcY + yy * srcHeight / dstHeight;
for( int yy = 0; yy < textHeight; yy++ ) {
int fontY = srcY + yy * boxSize / textHeight;
int* fontRow = fontPixels.GetRowPtr( fontY );
int dstY = y + yy;
int dstY = y + (yy + padding);
if( dstY >= dst.Height ) return;
int* dstRow = dst.GetRowPtr( dstY );
int xOffset = xMul * ((dstHeight - 1 - yy) / italicSize);
int xOffset = xMul * ((textHeight - 1 - yy) / italicSize);
for( int i = 0; i < runCount; i++ ) {
int srcX = (coords[i] & 0x0F) * boxSize;
int srcWidth = widths[coords[i]], dstWidth = dstWidths[i];
@ -141,11 +143,11 @@ namespace ClassicalSharp {
}
void DrawUnderline( FastBitmap dst, int x, int yOffset, ref DrawTextArgs args, bool shadowCol ) {
int height = PtToPx( args.Font.Size, boxSize );
int point = Utils.Floor( args.Font.Size );
int height = PtToPx( point, boxSize );
int offset = ShadowOffset( args.Font.Size );
int col = FastColour.White.ToArgb();
float point = args.Font.Size;
int col = FastColour.White.ToArgb();
string text = args.Text;
if( args.UseShadow ) height += offset;
int startX = x;
@ -175,8 +177,9 @@ namespace ClassicalSharp {
protected Size MeasureBitmappedSizeImpl( ref DrawTextArgs args ) {
if( String.IsNullOrEmpty( args.Text ) ) return Size.Empty;
float point = args.Font.Size;
Size total = new Size( 0, PtToPx( point, boxSize ) );
int textHeight = AdjTextSize( Utils.Floor( args.Font.Size ) );
Size total = new Size( 0, CellSize( textHeight ) );
int point = Utils.Floor( args.Font.Size );
for( int i = 0; i < args.Text.Length; i++ ) {
char c = args.Text[i];
@ -209,18 +212,26 @@ namespace ClassicalSharp {
return (int)'?';
}
protected static int ShadowOffset( float fontSize ) {
protected int ShadowOffset( float fontSize ) {
if( fontSize < 9.9f ) return 1;
if( fontSize < 24.9f ) return 2;
return 3;
}
protected int PtToPx( int point ) {
return (int)Math.Ceiling( (float)point / 72 * 96 ); // TODO: non 96 dpi?
protected int PtToPx( int point, int value ) {
return Utils.CeilDiv( value * point, boxSize );
}
protected int PtToPx( float point, float value ) {
return (int)Math.Ceiling( (value / boxSize) * point / 72f * 96f );
/// <summary> Rounds the given font size up to the nearest whole
/// multiple of the size of a character in default.png. </summary>
protected int AdjTextSize( int point ) {
return Utils.CeilDiv( point, boxSize ) * boxSize;
}
/// <summary> Returns the height of the bounding box that
/// contains both the given font size in addition to padding. </summary>
protected static int CellSize( int point ) {
return Utils.CeilDiv( point * 3, 2 );
}
protected void DisposeBitmappedText() {

View File

@ -19,7 +19,7 @@ namespace ClassicalSharp.Gui {
protected string titleText;
public override void Init() {
textFont = new Font( game.FontName, 14, FontStyle.Bold );
textFont = new Font( game.FontName, 16, FontStyle.Bold );
arrowFont = new Font( game.FontName, 18, FontStyle.Bold );
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
title = TextWidget.Create( game, 0, -130, titleText, Anchor.Centre, Anchor.Centre, titleFont );

View File

@ -82,8 +82,8 @@ namespace ClassicalSharp.Gui {
string Q( int value ) { return value == 1 ? "" : "s"; }
public override void Init() {
font = new Font( game.FontName, 13 );
posFont = new Font( game.FontName, 12, FontStyle.Italic );
font = new Font( game.FontName, 14 );
posFont = new Font( game.FontName, 13, FontStyle.Italic );
game.Events.ChatFontChanged += ChatFontChanged;
fpsTextWidget = new ChatTextWidget( game, font );

View File

@ -40,8 +40,7 @@ namespace ClassicalSharp.Gui {
public override void Init() {
base.Init();
regularFont = new Font( game.FontName, 16, FontStyle.Regular );
int size = game.Drawer2D.UseBitmappedChat ? 11 : 12;
extendedHelpFont = new Font( game.FontName, size, FontStyle.Regular );
extendedHelpFont = new Font( game.FontName, 13, FontStyle.Regular );
game.Keyboard.KeyRepeat = true;
}

View File

@ -24,8 +24,7 @@ namespace ClassicalSharp.Gui {
}
public override void Init() {
int size = game.Drawer2D.UseBitmappedChat ? 13 : 16;
titleFont = new Font( game.FontName, size, FontStyle.Bold );
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
}
public override void Dispose() {

View File

@ -96,15 +96,15 @@ namespace Launcher {
using( IDrawer2D drawer = Drawer ) {
drawer.SetBitmap( Framebuffer );
drawer.UseBitmappedChat = useBitmappedFont;
drawer.UseBitmappedChat = useBitmappedFont || ClassicBackground;
DrawTextArgs args = new DrawTextArgs( "&eClassical&fSharp", logoFont, false );
Size size = drawer.MeasureChatSize( ref args );
int xStart = Width / 2 - size.Width / 2;
args.Text = "&0Classical&0Sharp";
drawer.DrawChatText( ref args, xStart + 4, 8 + 4 );
drawer.DrawChatText( ref args, xStart + 3, 3 );
args.Text = "&eClassical&fSharp";
drawer.DrawChatText( ref args, xStart, 8 );
drawer.DrawChatText( ref args, xStart, 0 );
drawer.UseBitmappedChat = false;
}
}

View File

@ -70,7 +70,7 @@ namespace Launcher {
Window.WindowStateChanged += Resize;
Window.Keyboard.KeyDown += KeyDown;
LoadFont();
logoFont = new Font( FontName, 24, FontStyle.Regular );
logoFont = new Font( FontName, 32, FontStyle.Regular );
string path = Assembly.GetExecutingAssembly().Location;
Window.Icon = Icon.ExtractAssociatedIcon( path );
//Minimised = Window.WindowState == WindowState.Minimized;