Exemplo n.º 1
0
        /// <include file='doc\FontFamily.uex' path='docs/doc[@for="FontFamily.FontFamily1"]/*' />
        /// <devdoc>
        ///    Initializes a new instance of the <see cref='System.Drawing.FontFamily'/>
        ///    class in the specified <see cref='System.Drawing.Text.FontCollection'/> and with the specified name.
        /// </devdoc>
        public FontFamily(string name, FontCollection fontCollection)
        {
            IntPtr fontfamily = IntPtr.Zero;

            IntPtr nativeFontCollection = (fontCollection == null) ? IntPtr.Zero : fontCollection.nativeFontCollection;
            int    status = SafeNativeMethods.GdipCreateFontFamilyFromName(name, new HandleRef(fontCollection, nativeFontCollection), out fontfamily);

            // Special case this incredibly common error message to give more information
            if (status == SafeNativeMethods.FontFamilyNotFound)
            {
                throw new ArgumentException(SR.GetString(SR.GdiplusFontFamilyNotFound, name));
            }
            else if (status == SafeNativeMethods.NotTrueTypeFont)
            {
                throw new ArgumentException(SR.GetString(SR.GdiplusNotTrueTypeFont, name));
            }
            else if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            nativeFamily = fontfamily;
        }