private static Size MeasureTextInternal( IDeviceContext dc, ReadOnlySpan <char> text, Font?font, Size proposedSize, TextFormatFlags flags = TextFormatFlags.Bottom) { if (dc is null) { throw new ArgumentNullException(nameof(dc)); } if (text.IsEmpty) { return(Size.Empty); } // This MUST come before retreiving the HDC, which locks the Graphics object Gdi32.QUALITY quality = FontQualityFromTextRenderingHint(dc); // Applying state may not impact text size measurements. Rather than risk missing some // case we'll apply as we have historically to avoid suprise regressions. using var hdc = new DeviceContextHdcScope(dc, GetApplyStateFlags(dc, flags)); using var hfont = GdiCache.GetHFONT(font, quality, hdc); return(hdc.HDC.MeasureText(text, hfont, proposedSize, flags)); }
private static Size MeasureTextInternal( IDeviceContext dc, ReadOnlySpan <char> text, Font?font, Size proposedSize, TextFormatFlags flags = TextFormatFlags.Bottom, bool blockModifyString = false) { if (dc is null) { throw new ArgumentNullException(nameof(dc)); } User32.DT drawTextFlags = GetTextFormatFlags(flags, blockModifyString); if (text.IsEmpty) { return(Size.Empty); } // This MUST come before retreiving the HDC, which locks the Graphics object Gdi32.QUALITY quality = FontQualityFromTextRenderingHint(dc); using var hdc = new DeviceContextHdcScope(dc); using var hfont = GdiCache.GetHFONT(font, quality, hdc); return(hdc.MeasureText(text, hfont, proposedSize, drawTextFlags)); }
private static void DrawTextInternal( Gdi32.HDC hdc, ReadOnlySpan <char> text, Font?font, Rectangle bounds, Color foreColor, Gdi32.QUALITY fontQuality, Color backColor, TextFormatFlags flags) { using var hfont = GdiCache.GetHFONT(font, fontQuality, hdc); hdc.DrawText(text, hfont, bounds, foreColor, flags, backColor); }
internal static void DrawTextInternal( Gdi32.HDC hdc, string?text, Font?font, Rectangle bounds, Color foreColor, Gdi32.QUALITY fontQuality, Color backColor, User32.DT flags) { using var hfont = GdiCache.GetHFONT(font, fontQuality); hdc.DrawText(text, hfont, bounds, foreColor, flags, backColor); }
private static Size MeasureTextInternal( ReadOnlySpan<char> text, Font? font, Size proposedSize, TextFormatFlags flags = TextFormatFlags.Bottom) { if (text.IsEmpty) return Size.Empty; using var screen = GdiCache.GetScreenHdc(); using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.DEFAULT, screen); return screen.HDC.MeasureText(text, hfont, proposedSize, GetTextFormatFlags(flags)); }
private static Size MeasureTextInternal( string?text, Font?font, Size proposedSize, TextFormatFlags flags = TextFormatFlags.Bottom) { if (string.IsNullOrEmpty(text)) { return(Size.Empty); } using var hfont = GdiCache.GetHFONT(font); using var screen = GdiCache.GetScreenHdc(); return(screen.HDC.MeasureText(text, hfont, proposedSize, GetTextFormatFlags(flags))); }
private static Size MeasureTextInternal( ReadOnlySpan <char> text, Font?font, Size proposedSize, TextFormatFlags flags = TextFormatFlags.Bottom, bool blockModifyString = false) { User32.DT drawTextFlags = GetTextFormatFlags(flags, blockModifyString); if (text.IsEmpty) { return(Size.Empty); } using var screen = GdiCache.GetScreenHdc(); using var hfont = GdiCache.GetHFONT(font, Gdi32.QUALITY.DEFAULT, screen); return(screen.HDC.MeasureText(text, hfont, proposedSize, drawTextFlags)); }
private static Size MeasureTextInternal( IDeviceContext dc, string?text, Font?font, Size proposedSize, TextFormatFlags flags = TextFormatFlags.Bottom) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } if (string.IsNullOrEmpty(text)) { return(Size.Empty); } // This MUST come before retreiving the HDC, which locks the Graphics object Gdi32.QUALITY quality = FontQualityFromTextRenderingHint(dc); using var hdc = new DeviceContextHdcScope(dc); using var hfont = GdiCache.GetHFONT(font, quality); return(hdc.MeasureText(text, hfont, proposedSize, GetTextFormatFlags(flags))); }