public void Font_GetHeight(string family, float size, int height) { using Font font = new Font(family, size); if (font.Name != family) { // Not installed on this machine return; } using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE); Assert.Equal(height, hfont.Data.Height); }
public void Font_GetTextMargins(string family, float size, int left, int right) { using Font font = new Font(family, size); if (font.Name != family) { // Not installed on this machine return; } using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE); User32.DRAWTEXTPARAMS margins = hfont.GetTextMargins(); Assert.Equal(left, margins.iLeftMargin); Assert.Equal(right, margins.iRightMargin); }
public void Font_MeasureText(string family, float size, Size proposedSize, uint dt, Size expected) { using Font font = new Font(family, size); if (font.Name != family) { // Not installed on this machine return; } using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE); using var screen = GdiCache.GetScreenHdc(); Size measure = screen.HDC.MeasureText("Windows Foundation Classes", hfont, proposedSize, (User32.DT)dt); Assert.Equal(expected, measure); }
public void Font_GetTextExtent(string family, float size, int width, int height) { using Font font = new Font(family, size); if (font.Name != family) { // Not installed on this machine return; } using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE); using var screen = GdiCache.GetScreenHdc(); Size extent = screen.HDC.GetTextExtent("Whizzo Butter", hfont); Assert.Equal(width, extent.Width); Assert.Equal(height, extent.Height); }
public void Font_AdjustForVerticalAlignment(string family, float size, Rectangle bounds, uint dt, Rectangle expected) { using Font font = new Font(family, size); if (font.Name != family) { // Not installed on this machine return; } using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE); using var screen = GdiCache.GetScreenHdc(); using var fontSelection = new Gdi32.SelectObjectScope(screen, hfont.Object); User32.DRAWTEXTPARAMS param = default; Rectangle result = screen.HDC.AdjustForVerticalAlignment( "Windows Foundation Classes", bounds, (User32.DT)dt, ref param); Assert.Equal(expected, result); }