Beispiel #1
0
        public static Font FromLogFont(object lf, IntPtr hdc)
        {
            IntPtr  newObject;
            LOGFONT o      = (LOGFONT)lf;
            Status  status = GDIPlus.GdipCreateFontFromLogfont(hdc, ref o, out newObject);

            GDIPlus.CheckStatus(status);
            return(new Font(newObject, "Microsoft Sans Serif", FontStyle.Regular, 10));
        }
Beispiel #2
0
        public IntPtr ToHfont()
        {
            if (fontObject == IntPtr.Zero)
            {
                throw new ArgumentException(string.Format("Object has been disposed."));
            }

            if (GDIPlus.RunningOnUnix())
            {
                return(fontObject);
            }

            // win32 specific code
            if (olf == null)
            {
                olf = new LOGFONT();
                ToLogFont(olf);
            }
            LOGFONT lf = (LOGFONT)olf;

            return(GDIPlus.CreateFontIndirect(ref lf));
        }
Beispiel #3
0
        public static Font FromHfont(IntPtr hfont)
        {
            IntPtr    newObject;
            IntPtr    hdc;
            FontStyle newStyle = FontStyle.Regular;
            float     newSize;
            LOGFONT   lf = new LOGFONT();

            // Sanity. Should we throw an exception?
            if (hfont == IntPtr.Zero)
            {
                Font result = new Font("Arial", (float)10.0, FontStyle.Regular);
                return(result);
            }

            if (GDIPlus.RunningOnUnix())
            {
                // If we're on Unix we use our private gdiplus API to avoid Wine
                // dependencies in S.D
                Status s = GDIPlus.GdipCreateFontFromHfont(hfont, out newObject, ref lf);
                GDIPlus.CheckStatus(s);
            }
            else
            {
                // This needs testing
                // GetDC, SelectObject, ReleaseDC GetTextMetric and
                // GetFontFace are not really GDIPlus, see gdipFunctions.cs

                newStyle = FontStyle.Regular;

                hdc = GDIPlus.GetDC(IntPtr.Zero);
                try {
                    return(FromLogFont(lf, hdc));
                }
                finally {
                    GDIPlus.ReleaseDC(IntPtr.Zero, hdc);
                }
            }

            if (lf.lfItalic != 0)
            {
                newStyle |= FontStyle.Italic;
            }

            if (lf.lfUnderline != 0)
            {
                newStyle |= FontStyle.Underline;
            }

            if (lf.lfStrikeOut != 0)
            {
                newStyle |= FontStyle.Strikeout;
            }

            if (lf.lfWeight > 400)
            {
                newStyle |= FontStyle.Bold;
            }

            if (lf.lfHeight < 0)
            {
                newSize = lf.lfHeight * -1;
            }
            else
            {
                newSize = lf.lfHeight;
            }

            return(new Font(newObject, lf.lfFaceName, newStyle, newSize));
        }