private void CreateFont(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) { _originalFontName = familyName; FontFamily family; // NOTE: If family name is null, empty or invalid, // MS creates Microsoft Sans Serif font. try { family = new FontFamily(familyName); } catch (Exception) { family = FontFamily.GenericSansSerif; } Initialize(family, emSize, style, unit, charSet, isVertical); int status = Gdip.GdipCreateFont(new HandleRef(this, family.NativeFamily), emSize, style, unit, out _nativeFont); if (status == Gdip.FontStyleNotFound) { throw new ArgumentException($"Style {style} isn't supported by font {familyName}."); } Gdip.CheckStatus(status); }
public Font(Font prototype, FontStyle newStyle) { // no null checks, MS throws a NullReferenceException if original is null Initialize(prototype.FontFamily, prototype.Size, newStyle, prototype.Unit, prototype.GdiCharSet, prototype.GdiVerticalFont); int status = Gdip.GdipCreateFont(new HandleRef(_fontFamily, _fontFamily.NativeFamily), Size, Style, Unit, out _nativeFont); Gdip.CheckStatus(status); }
public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont) { if (family == null) { throw new ArgumentNullException(nameof(family)); } int status; Initialize(family, emSize, style, unit, gdiCharSet, gdiVerticalFont); status = Gdip.GdipCreateFont(new HandleRef(this, family.NativeFamily), emSize, style, unit, out _nativeFont); Gdip.CheckStatus(status); }
///<summary> /// Creates the GDI+ native font object. ///</summary> private void CreateNativeFont() { Debug.Assert(_nativeFont == IntPtr.Zero, "nativeFont already initialized, this will generate a handle leak."); Debug.Assert(_fontFamily != null, "fontFamily not initialized."); // Note: GDI+ creates singleton font family objects (from the corresponding font file) and reference count them so // if creating the font object from an external FontFamily, this object's FontFamily will share the same native object. int status = Gdip.GdipCreateFont( new HandleRef(this, _fontFamily.NativeFamily), _fontSize, _fontStyle, _fontUnit, out _nativeFont); // Special case this common error message to give more information if (status == Gdip.FontStyleNotFound) { throw new ArgumentException(SR.Format(SR.GdiplusFontStyleNotFound, _fontFamily.Name, _fontStyle.ToString())); } else if (status != Gdip.Ok) { throw Gdip.StatusException(status); } }