コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
        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));
        }
コード例 #6
0
        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)));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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)));
        }