Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static FontStyle ToEto(this NSFontTraitMask traits)
        {
            var style = FontStyle.None;

            if (traits.HasFlag(NSFontTraitMask.Bold))
            {
                style |= FontStyle.Bold;
            }
            if (traits.HasFlag(NSFontTraitMask.Italic))
            {
                style |= FontStyle.Italic;
            }
            //if (traits.HasFlag (NSFontTraitMask.Condensed))
            //	style |= FontStyle.Condensed;
            //if (traits.HasFlag (NSFontTraitMask.Narrow))
            //	style |= FontStyle.Light;
            return(style);
        }
Ejemplo n.º 3
0
 public static string ToDesignerString(this NSFontTraitMask mask)
 {
     if (mask.HasFlag(NSFontTraitMask.Bold))
     {
         return(string.Format("{0}.{1}", nameof(NSFontTraitMask), nameof(NSFontTraitMask.Bold)));
     }
     return("default(NSFontTraitMask)");
     //return string.Format("{0}.{1}", nameof(NSFontTraitMask), mask.ToString());
 }