Пример #1
0
        public static Font FromLogFont(object lf, IntPtr hdc)
        {
            IntPtr font   = IntPtr.Zero;
            int    status = Gdip.GdipCreateFontFromLogfontW(new HandleRef(null, hdc), lf, out font);

            // Special case this incredibly common error message to give more information
            if (status == Gdip.NotTrueTypeFont)
            {
                throw new ArgumentException(SR.GdiplusNotTrueTypeFont_NoName);
            }
            else if (status != Gdip.Ok)
            {
                throw Gdip.StatusException(status);
            }

            // GDI+ returns font = 0 even though the status is Ok.
            if (font == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Format(SR.GdiplusNotTrueTypeFont, lf.ToString()));
            }

#pragma warning disable 0618
            bool gdiVerticalFont = (Marshal.ReadInt16(lf, LogFontNameOffset) == (short)'@');
            return(new Font(font, Marshal.ReadByte(lf, LogFontCharSetOffset), gdiVerticalFont));

#pragma warning restore 0618
        }
Пример #2
0
        internal static Font FromLogFontInternal(ref Interop.User32.LOGFONT logFont, IntPtr hdc)
        {
            int status = Gdip.GdipCreateFontFromLogfontW(hdc, ref logFont, out IntPtr font);

            // Special case this incredibly common error message to give more information
            if (status == Gdip.NotTrueTypeFont)
            {
                throw new ArgumentException(SR.GdiplusNotTrueTypeFont_NoName);
            }
            else if (status != Gdip.Ok)
            {
                throw Gdip.StatusException(status);
            }

            // GDI+ returns font = 0 even though the status is Ok.
            if (font == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Format(SR.GdiplusNotTrueTypeFont, logFont.ToString()));
            }

            bool gdiVerticalFont = logFont.lfFaceName[0] == '@';

            return(new Font(font, logFont.lfCharSet, gdiVerticalFont));
        }