/// <summary> /// Returns a TEXTMETRIC structure for the font selected in the device context /// represented by this object, in units of pixels. /// </summary> public Gdi32.TEXTMETRICW GetTextMetrics() { // Set the mapping mode to MM_TEXT so we deal with units of pixels. Gdi32.MM mapMode = DeviceContext.MapMode; bool setupDC = mapMode != Gdi32.MM.TEXT; if (setupDC) { // Changing the MapMode will affect viewport and window extent and origin, we save the dc // state so all those properties can be properly restored once done. DeviceContext.SaveHdc(); } try { if (setupDC) { mapMode = DeviceContext.SetMapMode(Gdi32.MM.TEXT); } var tm = new Gdi32.TEXTMETRICW(); Gdi32.GetTextMetricsW(DeviceContext, ref tm); return(tm); } finally { if (setupDC) { DeviceContext.RestoreHdc(); } } }
internal static IEmfValidator TextOut( string text, Gdi32.MM mapMode = Gdi32.MM.TEXT, Gdi32.BKMODE backgroundMode = Gdi32.BKMODE.TRANSPARENT, string?fontFace = null, TextOutValidator.Flags validate = default) => new TextOutValidator( text, textColor: Color.Empty, mapMode, backgroundMode, fontFace, validate);
public TextOutValidator( string text, Color textColor, Rectangle?bounds, Gdi32.MM mapMode = default, Gdi32.BKMODE backgroundMode = default, string?fontFace = null, Flags validate = default) { _text = text; _textColor = textColor; _mapMode = mapMode; _backgroundMode = backgroundMode; _fontFace = fontFace; _bounds = bounds.HasValue ? bounds.Value : default; if (validate != default) { _validate = validate; } else { _validate = Flags.Text; if (bounds.HasValue) { _validate |= Flags.Bounds; } if (!textColor.IsEmpty) { _validate |= Flags.TextColor; } if (mapMode != default) { _validate |= Flags.MapMode; } if (backgroundMode != default) { _validate |= Flags.BackgroundMode; } if (!string.IsNullOrEmpty(fontFace)) { _validate |= Flags.FontFace; } } }