예제 #1
0
        /// <summary>
        /// Check if the font has a fixed width
        /// </summary>
        /// <param name="font">Font to check</param>
        /// <returns>true if the font has a fixed width</returns>
        public static bool IsFixedPitch(Font font)
        {
            bool result;

            IntPtr fnt = font.ToHfont();

            using (Bitmap bmp = new Bitmap(1, 1))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    IntPtr hdc = g.GetHdc();

                    // store the current font and set the new one
                    IntPtr fntOld = SelectObject(hdc, fnt);

                    TEXTMETRIC metric = new TEXTMETRIC();

                    NativeMethods.GetTextMetrics(hdc, ref metric);

                    result = (metric.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0;

                    // restore the old font
                    SelectObject(hdc, fntOld);

                    g.ReleaseHdc(hdc);
                }
            }

            DeleteObject(fnt);

            return(result);
        }
예제 #2
0
		/// <summary>
		/// Check if the font has a fixed width
		/// </summary>
		/// <param name="font">Font to check</param>
		/// <returns>true if the font has a fixed width</returns>
		public static bool IsFixedPitch(Font font)
		{
			bool result;

			IntPtr fnt = font.ToHfont();

			using (Bitmap bmp = new Bitmap(1, 1))
			{
				using (Graphics g = Graphics.FromImage(bmp))
				{
					IntPtr hdc = g.GetHdc();

					// store the current font and set the new one
					IntPtr fntOld = SelectObject(hdc, fnt);

					TEXTMETRIC metric = new TEXTMETRIC();

					NativeMethods.GetTextMetrics(hdc, ref metric);

					result = (metric.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0;

					// restore the old font
					SelectObject(hdc, fntOld);

					g.ReleaseHdc(hdc);
				}
			}

			DeleteObject(fnt);

			return result;
		}
            private TEXTMETRIC GenerateTextMetrics(Graphics graphics, Font font)
            {
                var        hDC        = IntPtr.Zero;
                TEXTMETRIC textMetric = new TEXTMETRIC();
                var        hFont      = IntPtr.Zero;

                try
                {
                    hDC   = graphics.GetHdc();
                    hFont = font.ToHfont();
                    IntPtr hFontDefault = SelectObject(hDC, hFont);
                    bool   result       = GetTextMetrics(hDC, ref textMetric);
                    SelectObject(hDC, hFontDefault);
                }
                finally
                {
                    if (hFont != IntPtr.Zero)
                    {
                        DeleteObject(hFont);
                    }
                    if (hDC != IntPtr.Zero)
                    {
                        graphics.ReleaseHdc(hDC);
                    }
                }
                return(textMetric);
            }
예제 #4
0
        public Font(string filename, int size, FontStyle style)
        {
//			Debug.Assert(false);
            string fontname = filename.Replace("/Application/", "./");

            this.__size  = size;
            this.__style = style;
            System.Drawing.FontStyle _style = System.Drawing.FontStyle.Regular;
            switch (style)
            {
            case FontStyle.Regular:
                _style = System.Drawing.FontStyle.Regular;
                break;

            case FontStyle.Bold:
                _style = System.Drawing.FontStyle.Bold;
                break;

            case FontStyle.Italic:
                _style = System.Drawing.FontStyle.Italic;
                break;
            }
            PrivateFontCollection privateFonts = new PrivateFontCollection();

            privateFonts.AddFontFile(fontname);

            //Arial
            //Comic Sans MS
            //MS Gothic
            this.__font = new System.Drawing.Font(privateFonts.Families[0], (int)(__size * 0.75f), _style);             //FIXME:???0.8
            //this.__font = new System.Drawing.Font("Arial", __size, _style); //FIXME:???0.8
            //this.__font = new System.Drawing.Font(/*"宋体"*/FontFamily.GenericSansSerif, __size, _style);

            this.__metrics = new FontMetrics();


            IntPtr hdc    = GetDC(IntPtr.Zero);
            IntPtr handle = __font.ToHfont();

            try
            {
                IntPtr     handle2    = SelectObject(hdc, handle);
                TEXTMETRIC tEXTMETRIC = new TEXTMETRIC();
                GetTextMetrics(hdc, ref tEXTMETRIC);
                __metrics.Ascent  = tEXTMETRIC.tmAscent;
                __metrics.Descent = tEXTMETRIC.tmDescent;
                __metrics.Leading = tEXTMETRIC.tmHeight - tEXTMETRIC.tmAscent - tEXTMETRIC.tmDescent;
                SelectObject(hdc, handle2);
            }
            finally
            {
                DeleteObject(handle);
                ReleaseDC(IntPtr.Zero, hdc);
            }
        }
예제 #5
0
        // GetTextMetrics wrapper
        public static void GetTextMetrics(Graphics graphics, Font font, ref TEXTMETRIC tm)
        {
            IntPtr hDC      = graphics.GetHdc();
            IntPtr hFont    = font.ToHfont();
            IntPtr oldHFont = SelectObject(hDC, hFont);

            GetTextMetricsA(hDC, ref tm);
            SelectObject(hDC, oldHFont);
            DeleteObject(hFont);
            graphics.ReleaseHdc(hDC);
        }
예제 #6
0
 public void Dispose()
 {
     HASH      = 0;
     HFONT     = (IntPtr)0;
     GLYPHINFO = null;
     METRIC    = default(TEXTMETRIC);
     glDeleteLists(
         LIST,
         256);
     LIST = 0;
 }
예제 #7
0
        public Font(FontAlias alias, int size, FontStyle style)
        {
            this.__alias = alias;
            this.__size  = size;
            this.__style = style;
            System.Drawing.FontStyle _style = System.Drawing.FontStyle.Regular;
            switch (style)
            {
            case FontStyle.Regular:
                _style = System.Drawing.FontStyle.Regular;
                break;

            case FontStyle.Bold:
                _style = System.Drawing.FontStyle.Bold;
                break;

            case FontStyle.Italic:
                _style = System.Drawing.FontStyle.Italic;
                break;
            }
            //Arial
            //Comic Sans MS
            //MS Gothic
            this.__font = new System.Drawing.Font("MS Gothic", (int)(__size * 0.75f), _style);             //FIXME:???0.8
            //this.__font = new System.Drawing.Font("Arial", __size, _style); //FIXME:???0.8
            //this.__font = new System.Drawing.Font(/*"宋体"*/FontFamily.GenericSansSerif, __size, _style);

            this.__metrics = new FontMetrics();


            IntPtr hdc    = GetDC(IntPtr.Zero);
            IntPtr handle = __font.ToHfont();

            try
            {
                IntPtr     handle2    = SelectObject(hdc, handle);
                TEXTMETRIC tEXTMETRIC = new TEXTMETRIC();
                GetTextMetrics(hdc, ref tEXTMETRIC);
                __metrics.Ascent  = tEXTMETRIC.tmAscent;
                __metrics.Descent = tEXTMETRIC.tmDescent;
                __metrics.Leading = tEXTMETRIC.tmHeight - tEXTMETRIC.tmAscent - tEXTMETRIC.tmDescent;
                SelectObject(hdc, handle2);
            }
            finally
            {
                DeleteObject(handle);
                ReleaseDC(IntPtr.Zero, hdc);
            }
        }
예제 #8
0
        public static int GetTextBaseline(Control ctrl, ContentAlignment alignment)
        {
            if (ctrl == null)
            {
                throw new ArgumentNullException("ctrl");
            }

            Rectangle ctrlRect = ctrl.ClientRectangle;

            int ascent = 0;
            int height = 0;

            using (Graphics grfx = ctrl.CreateGraphics())
            {
                IntPtr hDC   = grfx.GetHdc();
                IntPtr hFont = ctrl.Font.ToHfont();

                try
                {
                    IntPtr     oldFont    = Gdi32.SelectObject(hDC, hFont);
                    TEXTMETRIC textMetric = new TEXTMETRIC();

                    Gdi32.GetTextMetrics(hDC, textMetric);

                    ascent = textMetric.tmAscent + 1;
                    height = textMetric.tmHeight;

                    Gdi32.SelectObject(hDC, oldFont);
                }
                finally
                {
                    Gdi32.DeleteObject(hFont);
                    grfx.ReleaseHdc(hDC);
                }
            }

            if ((alignment & NuGenControlPaint.AnyTop) != 0)
            {
                return(ctrlRect.Top + ascent);
            }

            if ((alignment & NuGenControlPaint.AnyMiddle) != 0)
            {
                return(((ctrlRect.Top + (ctrlRect.Height / 2)) - (height / 2)) + ascent);
            }

            return((ctrlRect.Bottom - height) + ascent);
        }
예제 #9
0
 public static extern System.Int32 GetTextMetrics(System.Int32 hDC,ref TEXTMETRIC tm);
예제 #10
0
 private FontMetricsImpl(Graphics graphics, Font font)
 {
     this.metrics = this.GenerateTextMetrics(graphics, font);
 }
예제 #11
0
 // GetTextMetrics wrapper
 public static void GetTextMetrics(Graphics graphics, Font font, ref TEXTMETRIC tm)
 {
     IntPtr hDC = graphics.GetHdc();
     IntPtr hFont = font.ToHfont();
     IntPtr oldHFont = SelectObject(hDC, hFont);
     GetTextMetricsA(hDC, ref tm);
     SelectObject(hDC, oldHFont);
     DeleteObject(hFont);
     graphics.ReleaseHdc(hDC);
 }
예제 #12
0
 public void GetTextMetrics(ref TEXTMETRIC ATextMetric)
 {
     GDI.GetTextMetrics(FHandle, ref ATextMetric);
 }
예제 #13
0
파일: WinAPI.cs 프로젝트: KHCmaster/PPD
 internal static extern bool GetTextMetrics(IntPtr hdc, ref TEXTMETRIC lptm);
예제 #14
0
 public static extern int GetTextMetrics(
     IntPtr hdc,
     ref TEXTMETRIC lptm
     );
예제 #15
0
 [DllImport("gdi32.dll", CharSet = CharSet.Auto)] public static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC lptm);
예제 #16
0
 private static extern bool GetTextMetrics(HandleRef hdc, out TEXTMETRIC tm);
예제 #17
0
        protected override void WndProc(ref Message m)
        {
            var      message = (Utils.ControlExtensions.WindowsMessage)m.Msg;
            Graphics graphics;
            Keys     key;

            System.Drawing.SizeF size;
            System.Drawing.Point point;
            RectangleF           rect;
            SolidBrush           brush;
            Brush        fontBrush;
            StringFormat stringFormat;

            switch (message)
            {
            case ControlExtensions.WindowsMessage.CREATE:

                using (graphics = this.CreateGraphics())
                {
                    tm = graphics.GetTextMetrics(this.Font);
                }

                nCharX         = tm.tmAveCharWidth;
                nCharY         = tm.tmHeight;
                this.BackColor = SystemColors.Window;

                builder = new StringBuilder();

                break;

            case ControlExtensions.WindowsMessage.SIZE:

                var loHigh = m.LParam.ToLowHiWord();

                nWindowX      = loHigh.Low;
                nWindowCharsX = Math.Max(1, nWindowX / nCharX);

                nWindowY      = loHigh.High;
                nWindowCharsY = Math.Max(1, nWindowY / nCharY);

                if (caret != null)
                {
                    caret.Position = new System.Drawing.Point(0, 0);
                }

                break;

            case ControlExtensions.WindowsMessage.KEYDOWN:

                key = (Keys)m.WParam;

                switch (key)
                {
                case Keys.Home:
                    nCaretPosX = 0;
                    break;

                case Keys.End:
                    nCaretPosX = nWindowCharsX - 1;
                    break;

                case Keys.PageUp:
                    nCaretPosY = 0;
                    break;

                case Keys.PageDown:
                    nCaretPosY = nWindowCharsY - 1;
                    break;

                case Keys.Left:
                    nCaretPosX = Math.Max(nCaretPosX - 1, 0);
                    break;

                case Keys.Right:
                    nCaretPosX = Math.Min(nCaretPosX + 1, nWindowCharsX - 1);
                    break;

                case Keys.Up:
                    nCaretPosY = Math.Max(nCaretPosY - 1, 0);
                    break;

                case Keys.Down:
                    nCaretPosY = Math.Min(nCaretPosY + 1, nWindowCharsY - 1);
                    break;

                case Keys.Delete:

                    if (builder.Length > 0)
                    {
                        builder.RemoveEnd(1);

                        caret.Hide();

                        using (graphics = this.CreateGraphics())
                        {
                            brush        = new SolidBrush(this.BackColor);
                            fontBrush    = SystemBrushes.WindowText;
                            stringFormat = new StringFormat(StringFormatFlags.MeasureTrailingSpaces);

                            size  = graphics.MeasureString(this.Text, this.Font, int.MaxValue, stringFormat);
                            rect  = new RectangleF(0, 0, size.Width, size.Height);
                            point = new System.Drawing.Point((int)rect.Right, (int)rect.Top);

                            graphics.FillRectangle(brush, this.ClientRectangle);

                            graphics.DrawString(this.Text, this.Font, fontBrush, rect.Location);

                            brush.Dispose();
                        }

                        caret.Position = point;
                        caret.Show();
                    }

                    return;
                }

                break;

            case ControlExtensions.WindowsMessage.CHAR:

                var ch = (char)m.WParam;

                key = ch.ToKey();

                switch (key)
                {
                case Keys.Back:

                    this.SendMessage(ControlExtensions.WindowsMessage.KEYDOWN, (int)Keys.Delete, 1L);
                    break;

                case Keys.Tab:

                    do
                    {
                        this.SendMessage(ControlExtensions.WindowsMessage.CHAR, ' ', 1L);
                    }while (nCaretPosX % 4 != 0);

                    break;

                case Keys.Return:

                    nCaretPosX = 0;

                    if (++nCaretPosY == nWindowCharsY)
                    {
                        nCaretPosY = 0;
                    }

                    break;

                case Keys.Escape:
                case Keys.LineFeed:

                    this.Beep(ControlExtensions.BeepType.OK);
                    break;

                default:

                    builder.Append(key.ToAscii());

                    caret.Hide();

                    using (graphics = this.CreateGraphics())
                    {
                        brush        = new SolidBrush(this.BackColor);
                        fontBrush    = SystemBrushes.WindowText;
                        stringFormat = new StringFormat(StringFormatFlags.MeasureTrailingSpaces);

                        size  = graphics.MeasureString(this.Text, this.Font, int.MaxValue, stringFormat);
                        rect  = new RectangleF(0, 0, size.Width, size.Height);
                        point = new System.Drawing.Point((int)rect.Right, (int)rect.Top);

                        graphics.FillRectangle(brush, this.ClientRectangle);

                        graphics.DrawString(this.Text, this.Font, fontBrush, rect.Location);

                        brush.Dispose();
                    }

                    caret.Position = point;
                    caret.Show();

                    break;
                }

                break;

            case ControlExtensions.WindowsMessage.PAINT:

                break;

            case ControlExtensions.WindowsMessage.SETFOCUS:

                caret          = new Caret(this, 0, this.Height);
                caret.Position = new System.Drawing.Point(0, 0);
                caret.Show();

                break;

            case ControlExtensions.WindowsMessage.KILLFOCUS:

                if (caret != null)
                {
                    caret.Dispose();
                }

                break;
            }

            base.WndProc(ref m);
        }
예제 #18
0
		private static extern bool GetTextMetrics(IntPtr hdc, ref TEXTMETRIC lptm);
 public static bool GetTextMetrics(this DeviceContext deviceContext, out TEXTMETRIC metrics)
 => GdiMethods.GetTextMetrics(deviceContext, out metrics);
예제 #20
0
        //--------------------------------------------------------
        public static void PrintText(TextBox textIn, IntPtr hdc)
        {
            // Split input data into separate lines of text.
            char []   achNewLine = new char[] { '\n' };
            String [] astrSplit;
            astrSplit = textIn.Text.Split(achNewLine);

            // Calculate longest string in the document
            int cchMax = 0;
            int cstr   = astrSplit.Length;

            for (int i = 0; i < cstr; i++)
            {
                if (astrSplit[i].Length > cchMax)
                {
                    cchMax = astrSplit[i].Length;
                }
            }

            // Allocate conversion buffers.
            byte[] byteData = new Byte[cchMax];
            char[] chData   = new Char[cchMax];
            System.Text.Encoder d;
            d = System.Text.Encoding.UTF8.GetEncoder();

            // Get device resolution
            int cxyInch =
                GdiGraphics.GetDeviceCaps(hdc, CAPS.LOGPIXELSY);

            // In draft mode, the PCL driver returns wrong value.
            if (cxyInch == 0)
            {
                cxyInch = 150;
            }

            // Calculate page size.
            int cxPhysPage =
                GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALWIDTH);
            int cyPhysPage =
                GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALHEIGHT);
            int cxOff =
                GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALOFFSETX);
            int cyOff =
                GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALOFFSETY);

            // Calculate line height.
            TEXTMETRIC tm = new TEXTMETRIC();

            GdiFont.GetTextMetrics(hdc, ref tm);
            int cyLineHeight = tm.tmHeight + tm.tmExternalLeading;

            // Init text drawing coordinates;
            int xText = cxyInch - cxOff;
            int yText = cxyInch - cyOff;

            // Calculate page boundaries
            int yFirst = yText;
            int yLast  = cyPhysPage - cxyInch;

            // Notify GDI of document and page start.
            DOCINFO di = new DOCINFO();

            di.cbSize = Marshal.SizeOf(di);
            Printing.StartDoc(hdc, ref di);
            Printing.StartPage(hdc);

            try
            {
                // Set iEnd -- trim extra carriage-return from text
                int  iEnd      = 0;
                int  cchString = astrSplit[0].Length;
                char ch        = astrSplit[0][cchString - 1];
                if (ch == '\r')
                {
                    iEnd = -1;
                }

                // Loop through list of strings.
                for (int i = 0; i < cstr; i++)
                {
                    cchString = astrSplit[i].Length;
                    if (cchString > 0)
                    {
                        // Draw line of text.
                        GdiGraphics.ExtTextOut(hdc, xText, yText, 0,
                                               IntPtr.Zero, astrSplit[i], cchString + iEnd,
                                               IntPtr.Zero);
                    }

                    // Advance to next line.
                    yText += cyLineHeight;

                    // Skip to next page (if not at document end)
                    if (yText >= yLast && (i + 1) < cstr)
                    {
                        Printing.EndPage(hdc);
                        Printing.StartPage(hdc);
                        yText = yFirst;
                    }
                }
            }
            finally
            {
                // End of page & end of document.
                Printing.EndPage(hdc);
                Printing.EndDoc(hdc);
            }
        } // PrintText()
예제 #21
0
 internal static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC tm);
예제 #22
0
 public static extern bool GetTextMetrics(Win32DCSafeHandle hdc, out TEXTMETRIC tm);
예제 #23
0
 public static extern int GetTextMetricsA(IntPtr hDC, ref TEXTMETRIC tm);
예제 #24
0
		}; 

		//**********************************************************************
		[DllImport("gdi32.dll")] public extern static int
예제 #25
0
 public static extern bool GetTextMetricsW(
     DeviceContext hdc,
     out TEXTMETRIC lptm);
예제 #26
0
 public static extern bool GetTextMetrics(IntPtr dc, out TEXTMETRIC metric);
예제 #27
0
 public static bool GetTextMetrics(DeviceContext deviceContext, out TEXTMETRIC metrics)
 {
     return(Imports.GetTextMetricsW(deviceContext, out metrics));
 }
예제 #28
0
 public static extern bool GetTextMetrics(HandleRef hdc, TEXTMETRIC tm);
예제 #29
0
    public Bitmap TextRenderHQ(int _size, string _font, string _color, int _offset, string _str, bool _shadow)
    {
        privateFonts = new PrivateFontCollection();
        privateFonts.AddFontFile(_font);
        font = new Font(privateFonts.Families[0], _size);

        String s = _str;

        String[] rgbs   = _color.Split(new Char[] { ' ', ',', ';', ':' });
        Color[]  colors = new Color[rgbs.Length];
        for (Int32 i = 0; i < rgbs.Length; i++)
        {
            colors[i] = HexColorToColor(rgbs[i]);
        }

        Bitmap     bmp     = new Bitmap(10, 10, PixelFormat.Format24bppRgb);
        Graphics   g       = Graphics.FromImage(bmp);
        IntPtr     hdc     = g.GetHdc();
        IntPtr     oldfont = Gdi.SelectObject(hdc, font.ToHfont());
        TEXTMETRIC tm      = new TEXTMETRIC();

        Gdi.GetTextMetrics(hdc, ref tm);
        Int32 totalwidth = 0;

        Int32[] width  = new Int32[1];
        Int32[] widths = new Int32[s.Length];

        Graphics gs = Graphics.FromImage(new Bitmap(1, 1));

        for (Int32 i = 0; i < s.Length; i++)
        {
            Gdi.GetCharWidth(hdc, s[i], s[i], width);

            SizeF sizeW = gs.MeasureString(s[i].ToString(), new Font(_font, _size));
            if (s[i] >= 0x4e00 && s[i] <= 0x9fbb)
            {
                widths[i] = (int)sizeW.Width - _offset;
            }
            else
            {
                widths[i] = width[0];
            }
        }

        SizeF sizeF = gs.MeasureString(s, font);

        totalwidth = (int)sizeF.Width;

        Gdi.SelectObject(hdc, oldfont);
        g.ReleaseHdc(hdc);
        g.Dispose();
        bmp.Dispose();
        LayeredImage image = new LayeredImage(totalwidth + 4, tm.tmHeight + 4 + 4);
        Layer        bg    = image.Layers.Add();

        bg.Clear(Color.Black);
        bg.DrawText(0, 0, s, font, new SolidBrush(Color.White));
        Layer copybg = image.Layers.Copy(bg);

        copybg.Blur(4, 4);
        Layer white = image.Layers.Add();

        white.Clear(Color.White);

        if (_shadow)
        {
            Layer shadow = image.Layers.Copy(copybg);
            shadow.Invert();
            shadow.Opacity  = 0.5;
            shadow.OffsetX += 4;
            shadow.OffsetY += 4;
        }

        Int32 offsetx    = 0;
        Int32 colorindex = 0;
        Layer final      = image.Layers.Add();

        for (Int32 i = 0; i < s.Length; i++)
        {
            Color c = colors[colorindex];
            colorindex++;
            if (colorindex >= colors.Length)
            {
                colorindex = 0;
            }
            SolidBrush brush = new SolidBrush(c);
            final.FillRectangle(offsetx, 0, widths[i], tm.tmHeight, brush);
            offsetx += widths[i];
        }
        final.BumpMap(copybg, 135, 45, 3, false);
        final.Mask = (FastBitmap)bg.Bitmap.Clone();
        FastBitmap result = image.Flatten();

        result._bitmap.MakeTransparent();
        return(result._bitmap);
    }
예제 #30
0
		internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
예제 #31
0
 public static extern int GetTextMetricsA(IntPtr hDC, ref TEXTMETRIC tm);
 public static extern bool GetTextMetrics( IntPtr hdc, out TEXTMETRIC lptm );
예제 #33
0
 public static extern bool GetTextMetrics(HandleRef hdc, TEXTMETRIC tm);
예제 #34
0
 private FontMetricsImpl(Graphics graphics, Font font)
 {
     this.metrics = this.GenerateTextMetrics(graphics, font);
 }
예제 #35
0
		public static int GetTextBaseline(Control ctrl, System.Drawing.ContentAlignment alignment)
		{
			Rectangle clientRectangle = ctrl.ClientRectangle;
			int num = 0;
			int num2 = 0;
			using (Graphics graphics = ctrl.CreateGraphics())
			{
				IntPtr hdc = graphics.GetHdc();
				IntPtr handle = ctrl.Font.ToHfont();
				try
				{
					IntPtr handle2 = SelectObject(new HandleRef(ctrl, hdc), new HandleRef(ctrl, handle));
					TEXTMETRIC tEXTMETRIC = new TEXTMETRIC();
					GetTextMetrics(new HandleRef(ctrl, hdc), tEXTMETRIC);
					num = tEXTMETRIC.tmAscent + 1;
					num2 = tEXTMETRIC.tmHeight;
					SelectObject(new HandleRef(ctrl, hdc), new HandleRef(ctrl, handle2));
				}
				finally
				{
					DeleteObject(new HandleRef(ctrl.Font, handle));
					graphics.ReleaseHdc(hdc);
				}
			}
			if ((alignment & (System.Drawing.ContentAlignment)7) != (System.Drawing.ContentAlignment)0)
			{
				return clientRectangle.Top + num;
			}
			if ((alignment & (System.Drawing.ContentAlignment)112) != (System.Drawing.ContentAlignment)0)
			{
				return clientRectangle.Top + clientRectangle.Height / 2 - num2 / 2 + num;
			}
			return clientRectangle.Bottom - num2 + num;
		}
 private FontMetricsImpl(Graphics graphics, Font font)
 {
     metrics = GenerateTextMetrics(graphics, font);
 }
예제 #37
0
		internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
			IntPtr		dc;
			IntPtr		prevobj;
			TEXTMETRIC	tm;

			tm = new TEXTMETRIC();

			dc = Win32GetDC (IntPtr.Zero);
			prevobj = Win32SelectObject (dc, font.ToHfont ());
			
			if (Win32GetTextMetrics (dc, ref tm) == false) {
				prevobj = Win32SelectObject (dc, prevobj);
				Win32DeleteObject (prevobj);
				Win32ReleaseDC (IntPtr.Zero, dc);
				ascent = 0;
				descent = 0;
				return false;
			}
			prevobj = Win32SelectObject (dc, prevobj);
			Win32DeleteObject (prevobj);
			Win32ReleaseDC (IntPtr.Zero, dc);

			ascent = tm.tmAscent;
			descent = tm.tmDescent;

			return true;
		}
예제 #38
0
 public static extern bool GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
예제 #39
0
 public static extern Boolean GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
예제 #40
0
		[DllImport("gdi32.dll", CharSet = CharSet.Auto)] public static extern bool GetTextMetrics( IntPtr hdc, out TEXTMETRIC lptm );
예제 #41
0
 public static extern bool GetTextMetrics([In] SafeHandle hDC, [Out] out TEXTMETRIC lptm);
예제 #42
0
 private FontMetricsImpl(Graphics graphics, System.Drawing.Font font)
 {
     this.metrics = this.GenerateTextMetrics(graphics, font);
 }
예제 #43
0
 public static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC lptm);
예제 #44
0
 static extern bool GetTextMetrics(DeviceContextSafeHandle hdc, out TEXTMETRIC lptm);