Beispiel #1
0
        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)
        {
            int retVal;

            if (Marshal.SystemDefaultCharSize == 1)
            {
                // ANSI
                IntNativeMethods.TEXTMETRICA lptmA = new IntNativeMethods.TEXTMETRICA();
                retVal = IntUnsafeNativeMethods.GetTextMetricsA(hDC, ref lptmA);

                lptm.tmHeight           = lptmA.tmHeight;
                lptm.tmAscent           = lptmA.tmAscent;
                lptm.tmDescent          = lptmA.tmDescent;
                lptm.tmInternalLeading  = lptmA.tmInternalLeading;
                lptm.tmExternalLeading  = lptmA.tmExternalLeading;
                lptm.tmAveCharWidth     = lptmA.tmAveCharWidth;
                lptm.tmMaxCharWidth     = lptmA.tmMaxCharWidth;
                lptm.tmWeight           = lptmA.tmWeight;
                lptm.tmOverhang         = lptmA.tmOverhang;
                lptm.tmDigitizedAspectX = lptmA.tmDigitizedAspectX;
                lptm.tmDigitizedAspectY = lptmA.tmDigitizedAspectY;
                lptm.tmFirstChar        = (char)lptmA.tmFirstChar;
                lptm.tmLastChar         = (char)lptmA.tmLastChar;
                lptm.tmDefaultChar      = (char)lptmA.tmDefaultChar;
                lptm.tmBreakChar        = (char)lptmA.tmBreakChar;
                lptm.tmItalic           = lptmA.tmItalic;
                lptm.tmUnderlined       = lptmA.tmUnderlined;
                lptm.tmStruckOut        = lptmA.tmStruckOut;
                lptm.tmPitchAndFamily   = lptmA.tmPitchAndFamily;
                lptm.tmCharSet          = lptmA.tmCharSet;
            }
            else
            {
                // Unicode
                retVal = IntUnsafeNativeMethods.GetTextMetricsW(hDC, ref lptm);
            }

            DbgUtil.AssertWin32(retVal != 0, "GetTextMetrics(hdc=[0x{0:X8}], [out TEXTMETRIC] failed.", unchecked ((int)hDC.Handle));
            return(retVal);
        }
Beispiel #3
0
        /// <devdoc>
        ///     Returns a TEXTMETRIC structure for the font selected in the device context
        ///     represented by this object, in units of pixels.
        /// </devdoc>
        public IntNativeMethods.TEXTMETRIC GetTextMetrics()
        {
            IntNativeMethods.TEXTMETRIC tm = new IntNativeMethods.TEXTMETRIC();
            HandleRef hdc = new HandleRef(this.dc, this.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);
        }
Beispiel #4
0
 public static extern int GetTextMetricsW(HandleRef hDC, [In, Out] ref IntNativeMethods.TEXTMETRIC lptm);
        /// <devdoc>
        ///     Returns a TEXTMETRIC structure for the font selected in the device context 
        ///     represented by this object, in units of pixels.
        /// </devdoc>
        public IntNativeMethods.TEXTMETRIC GetTextMetrics()
        {
            IntNativeMethods.TEXTMETRIC tm  = new IntNativeMethods.TEXTMETRIC();
            HandleRef                   hdc = new HandleRef( this.dc, this.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 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;
 }