public static NSFont CreateFont(FontFamilyHandler familyHandler, float size, NSFontTraitMask traits, int weight = 5) { var font = NSFontManager.SharedFontManager.FontWithFamily(familyHandler.MacName, traits, weight, size); if (font == null) { if (traits.HasFlag(NSFontTraitMask.Italic)) { // fake italics by transforming the font const float kRotationForItalicText = 14.0f; var fontTransform = new NSAffineTransform(); fontTransform.Scale(size); var italicTransform = new NSAffineTransform(); italicTransform.TransformStruct = Matrix.FromSkew(0, kRotationForItalicText).ToCG(); fontTransform.AppendTransform(italicTransform); traits &= ~NSFontTraitMask.Italic; font = NSFontManager.SharedFontManager.FontWithFamily(familyHandler.MacName, traits, 5, size); if (font != null) { font = NSFont.FromDescription(font.FontDescriptor, fontTransform); } } } return(font); }
public static NSFont CreateFont(FontFamilyHandler familyHandler, float size, NSFontTraitMask traits, int weight = 5) { return(CreateFont(familyHandler.MacName, size, traits, weight)); }