Example #1
0
        private void Initialize(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)
        {
#if DEBUG
            if (CompModSwitches.LifetimeTracing.Enabled)
            {
                stackOnCreate = new System.Diagnostics.StackTrace().ToString();
            }
#endif

            if (family == null)
            {
                throw new ArgumentNullException("family");
            }
            if (emSize == float.NaN ||
                emSize == float.NegativeInfinity ||
                emSize == float.PositiveInfinity ||
                emSize <= 0 ||
                emSize > float.MaxValue)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidBoundArgument, "emSize", emSize, 0, "System.Single.MaxValue"), "emSize");
            }
            IntPtr font = IntPtr.Zero;

            int status = SafeNativeMethods.GdipCreateFont(new HandleRef(family, family.nativeFamily),
                                                          emSize,
                                                          style,
                                                          unit,
                                                          out font);

            // Special case this common error message to give more information
            if (status == SafeNativeMethods.FontStyleNotFound)
            {
                throw new ArgumentException(SR.GetString(SR.GdiplusFontStyleNotFound, family.Name, style.ToString()));
            }
            else if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            SetNativeFont(font);
            this.gdiCharSet      = gdiCharSet;
            this.gdiVerticalFont = gdiVerticalFont;
        }