public static int GetTextMetrics(HandleRef hDC, ref IntNativeMethods.TEXTMETRIC lptm) { int retVal = IntUnsafeNativeMethods.GetTextMetricsW(hDC, ref lptm); DbgUtil.AssertWin32(retVal != 0, "GetTextMetrics(hdc=[0x{0:X8}], [out TEXTMETRIC] failed.", hDC.Handle); return(retVal); }
public static int GetTextMetrics(HandleRef hDC, ref IntNativeMethods.TEXTMETRIC lptm) { if (Marshal.SystemDefaultCharSize == 1) { IntNativeMethods.TEXTMETRICA textmetrica = new IntNativeMethods.TEXTMETRICA(); int textMetricsA = GetTextMetricsA(hDC, ref textmetrica); lptm.tmHeight = textmetrica.tmHeight; lptm.tmAscent = textmetrica.tmAscent; lptm.tmDescent = textmetrica.tmDescent; lptm.tmInternalLeading = textmetrica.tmInternalLeading; lptm.tmExternalLeading = textmetrica.tmExternalLeading; lptm.tmAveCharWidth = textmetrica.tmAveCharWidth; lptm.tmMaxCharWidth = textmetrica.tmMaxCharWidth; lptm.tmWeight = textmetrica.tmWeight; lptm.tmOverhang = textmetrica.tmOverhang; lptm.tmDigitizedAspectX = textmetrica.tmDigitizedAspectX; lptm.tmDigitizedAspectY = textmetrica.tmDigitizedAspectY; lptm.tmFirstChar = (char)textmetrica.tmFirstChar; lptm.tmLastChar = (char)textmetrica.tmLastChar; lptm.tmDefaultChar = (char)textmetrica.tmDefaultChar; lptm.tmBreakChar = (char)textmetrica.tmBreakChar; lptm.tmItalic = textmetrica.tmItalic; lptm.tmUnderlined = textmetrica.tmUnderlined; lptm.tmStruckOut = textmetrica.tmStruckOut; lptm.tmPitchAndFamily = textmetrica.tmPitchAndFamily; lptm.tmCharSet = textmetrica.tmCharSet; return(textMetricsA); } return(GetTextMetricsW(hDC, ref lptm)); }
public IntNativeMethods.TEXTMETRIC GetTextMetrics() { IntNativeMethods.TEXTMETRIC lptm = new IntNativeMethods.TEXTMETRIC(); HandleRef hDC = new HandleRef(this.dc, this.dc.Hdc); bool flag = this.dc.MapMode != DeviceContextMapMode.Text; if (flag) { this.dc.SaveHdc(); } try { if (flag) { DeviceContextMapMode mode = this.dc.SetMapMode(DeviceContextMapMode.Text); } IntUnsafeNativeMethods.GetTextMetrics(hDC, ref lptm); } finally { if (flag) { this.dc.RestoreHdc(); } } return(lptm); }
/// <summary> /// Returns a TEXTMETRIC structure for the font selected in the device context /// represented by this object, in units of pixels. /// </summary> public IntNativeMethods.TEXTMETRIC GetTextMetrics() { IntNativeMethods.TEXTMETRIC tm = new IntNativeMethods.TEXTMETRIC(); HandleRef hdc = new HandleRef(dc, dc.Hdc); // Set the mapping mode to MM_TEXT so we deal with units of pixels. DeviceContextMapMode mapMode = dc.MapMode; bool setupDC = mapMode != DeviceContextMapMode.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. dc.SaveHdc(); } try { if (setupDC) { mapMode = dc.SetMapMode(DeviceContextMapMode.Text); } IntUnsafeNativeMethods.GetTextMetrics(hdc, ref tm); } finally { if (setupDC) { dc.RestoreHdc(); } } return(tm); }
public static extern int GetTextMetricsW(HandleRef hDC, [In, Out] ref IntNativeMethods.TEXTMETRIC lptm);