// Creates the native font family object. // Note: GDI+ creates singleton font family objects (from the corresponding font file) and reference count them. private void CreateFontFamily(string name, FontCollection fontCollection) { IntPtr fontfamily = IntPtr.Zero; IntPtr nativeFontCollection = (fontCollection == null) ? IntPtr.Zero : fontCollection._nativeFontCollection; int status = Gdip.GdipCreateFontFamilyFromName(name, new HandleRef(fontCollection, nativeFontCollection), out fontfamily); if (status != Gdip.Ok) { if (_createDefaultOnFail) { fontfamily = GetGdipGenericSansSerif(); // This throws if failed. } else { // Special case this incredibly common error message to give more information. if (status == Gdip.FontFamilyNotFound) { throw new ArgumentException(SR.Format(SR.GdiplusFontFamilyNotFound, name)); } else if (status == Gdip.NotTrueTypeFont) { throw new ArgumentException(SR.Format(SR.GdiplusNotTrueTypeFont, name)); } else { throw Gdip.StatusException(status); } } } SetNativeFamily(fontfamily); }