示例#1
0
        public override object SetStretch(object handle, FontStretch stretch)
        {
            FontData f = (FontData)handle;

            f = f.Copy();

            NSFont font = f.Font;

            if (stretch < FontStretch.SemiCondensed)
            {
                font = NSFontManager.SharedFontManager.ConvertFont(font, NSFontTraitMask.Condensed);
                font = NSFontManager.SharedFontManager.ConvertFontToNotHaveTrait(font, NSFontTraitMask.Compressed | NSFontTraitMask.Expanded | NSFontTraitMask.Narrow);
            }
            if (stretch == FontStretch.SemiCondensed)
            {
                font = NSFontManager.SharedFontManager.ConvertFont(font, NSFontTraitMask.Narrow);
                font = NSFontManager.SharedFontManager.ConvertFontToNotHaveTrait(font, NSFontTraitMask.Compressed | NSFontTraitMask.Expanded | NSFontTraitMask.Condensed);
            }
            else if (stretch > FontStretch.Normal)
            {
                font = NSFontManager.SharedFontManager.ConvertFont(font, NSFontTraitMask.Expanded);
                font = NSFontManager.SharedFontManager.ConvertFontToNotHaveTrait(font, NSFontTraitMask.Compressed | NSFontTraitMask.Narrow | NSFontTraitMask.Condensed);
            }
            else
            {
                font = NSFontManager.SharedFontManager.ConvertFontToNotHaveTrait(font, NSFontTraitMask.Condensed | NSFontTraitMask.Expanded | NSFontTraitMask.Narrow | NSFontTraitMask.Compressed);
            }
            f.Font    = font;
            f.Stretch = stretch;
            return(f);
        }
示例#2
0
        public override object Create(string fontName, double size, FontStyle style, FontWeight weight, FontStretch stretch)
        {
            var t = GetStretchTrait(stretch) | GetStyleTrait(style);

            var    names = fontName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            NSFont f     = null;

            foreach (var name in names)
            {
                f = NSFontManager.SharedFontManager.FontWithFamily(name.Trim(), t, weight.ToMacValue(), (float)size);
                if (f != null)
                {
                    break;
                }
            }
            if (f == null)
            {
                return(null);
            }

            var fd = FontData.FromFont(NSFontManager.SharedFontManager.ConvertFont(f, t));

            fd.Style   = style;
            fd.Weight  = weight;
            fd.Stretch = stretch;
            return(fd);
        }
示例#3
0
        public override object Copy(object handle)
        {
            FontData f = (FontData)handle;

            f      = f.Copy();
            f.Font = (NSFont)f.Font.Copy();
            return(f);
        }
示例#4
0
        public override object SetFamily(object handle, string family)
        {
            FontData f = (FontData)handle;

            f      = f.Copy();
            f.Font = NSFontManager.SharedFontManager.ConvertFontToFamily(f.Font, family);
            return(f);
        }
示例#5
0
        public override object SetSize(object handle, double size)
        {
            FontData f = (FontData)handle;

            f      = f.Copy();
            f.Font = NSFontManager.SharedFontManager.ConvertFont(f.Font, (float)size);
            return(f);
        }
示例#6
0
        public override object SetWeight(object handle, FontWeight weight)
        {
            FontData f = (FontData)handle;

            f        = f.Copy();
            f.Font   = f.Font.WithWeight(weight);
            f.Weight = weight;
            return(f);
        }
示例#7
0
        public override object Create(string fontName, double size, FontStyle style, FontWeight weight, FontStretch stretch)
        {
            var t  = GetStretchTrait(stretch) | GetStyleTrait(style);
            var f  = NSFontManager.SharedFontManager.FontWithFamily(fontName, t, GetWeightValue(weight), (float)size);
            var fd = FontData.FromFont(NSFontManager.SharedFontManager.ConvertFont(f, t));

            fd.Style   = style;
            fd.Weight  = weight;
            fd.Stretch = stretch;
            return(fd);
        }
示例#8
0
 public override IEnumerable <KeyValuePair <string, object> > GetAvailableFamilyFaces(string family)
 {
     foreach (var nsFace in NSFontManager.SharedFontManager.AvailableMembersOfFontFamily(family))
     {
         var name   = NSString.FromHandle(nsFace.ValueAt(1));
         var weight = ((NSNumber)NSValue.ValueFromPointer(nsFace.ValueAt(2)).NonretainedObjectValue).Int32Value;
         var traits = (NSFontTraitMask)((NSNumber)NSValue.ValueFromPointer(nsFace.ValueAt(3)).NonretainedObjectValue).Int32Value;
         yield return(new KeyValuePair <string, object>(name, FontData.FromFamily(family, traits, weight, 0)));
     }
     yield break;
 }
示例#9
0
        public override object SetWeight(object handle, FontWeight weight)
        {
            FontData f = (FontData)handle;

            f = f.Copy();
            int w = GetWeightValue(weight);

            f.Font   = NSFontManager.SharedFontManager.FontWithFamily(f.Font.FamilyName, NSFontManager.SharedFontManager.TraitsOfFont(f.Font), w, f.Font.PointSize);
            f.Weight = weight;
            return(f);
        }
示例#10
0
        public override object SetWeight(object handle, FontWeight weight)
        {
            FontData f = (FontData)handle;

            f = f.Copy();
            int w      = GetWeightValue(weight);
            var traits = NSFontManager.SharedFontManager.TraitsOfFont(f.Font);

            traits  |= weight >= FontWeight.Bold ? NSFontTraitMask.Bold : NSFontTraitMask.Unbold;
            traits  &= weight >= FontWeight.Bold ? ~NSFontTraitMask.Unbold : ~NSFontTraitMask.Bold;
            f.Font   = NSFontManager.SharedFontManager.FontWithFamily(f.Font.FamilyName, traits, w, f.Font.PointSize);
            f.Weight = weight;
            return(f);
        }
        public bool Run(IWindowFrameBackend parent)
        {
            fontPanel.Delegate = new FontPanelDelegate();

            if (SelectedFont != null)
            {
                NSFontManager.SharedFontManager.SetSelectedFont(((FontData)Toolkit.GetBackend(SelectedFont)).Font, false);
            }

            NSApplication.SharedApplication.RunModalForWindow(fontPanel);

            var font = NSFontPanel.SharedFontPanel.PanelConvertFont(NSFont.SystemFontOfSize(0));

            SelectedFont = Font.FromName(FontData.FromFont(font).ToString());

            return(true);
        }
示例#12
0
        public override object SetStyle(object handle, FontStyle style)
        {
            FontData f = (FontData)handle;

            f = f.Copy();
            NSFontTraitMask mask;

            if (style == FontStyle.Italic || style == FontStyle.Oblique)
            {
                mask = NSFontTraitMask.Italic;
            }
            else
            {
                mask = NSFontTraitMask.Unitalic;
            }
            f.Font  = NSFontManager.SharedFontManager.ConvertFont(f.Font, mask);
            f.Style = style;
            return(f);
        }
示例#13
0
        public override object SetFamily(object handle, string family)
        {
            FontData f = (FontData)handle;

            f = f.Copy();

            var    names = family.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            NSFont font  = null;

            foreach (var name in names)
            {
                font = NSFontManager.SharedFontManager.ConvertFontToFamily(f.Font, name.Trim());
                if (font != null)
                {
                    f.Font = font;
                    break;
                }
            }

            return(f);
        }
示例#14
0
 public override object GetSystemDefaultFont()
 {
     return(FontData.FromFont(NSFont.SystemFontOfSize(0)));
 }
示例#15
0
        public override FontStretch GetStretch(object handle)
        {
            FontData f = (FontData)handle;

            return(f.Stretch);
        }
示例#16
0
        public override FontWeight GetWeight(object handle)
        {
            FontData f = (FontData)handle;

            return(f.Weight);
        }
示例#17
0
        public override FontStyle GetStyle(object handle)
        {
            FontData f = (FontData)handle;

            return(f.Style);
        }
示例#18
0
        public override string GetFamily(object handle)
        {
            FontData f = (FontData)handle;

            return(f.Font.FamilyName);
        }
示例#19
0
        public override double GetSize(object handle)
        {
            FontData f = (FontData)handle;

            return(f.Font.PointSize);
        }