コード例 #1
0
        public static NSAttributedString ToAttributed(this Span span, Font defaultFont, Color defaultForegroundColor)
        {
            if (span == null)
            {
                return((NSAttributedString)null);
            }
            Color color = span.ForegroundColor;

            if (color.IsDefault)
            {
                color = defaultForegroundColor;
            }
            if (color.IsDefault)
            {
                color = Color.Black;
            }

            Font self = span.Font != Font.Default ? span.Font : defaultFont;
            var  font = self == Font.Default ? (NSFont)null : FontExtensions.ToUIFont(self);

            return(new NSAttributedString(
                       span.Text,
                       font,
                       ColorExtensions.ToUIColor(color),
                       ColorExtensions.ToUIColor(span.BackgroundColor),
                       null,                  // NSColor strokeColor = null,
                       null,                  // NSColor underlineColor = null,
                       null,                  // NSColor strikethroughColor = null,
                       NSUnderlineStyle.None, // UnderlineStyle
                       NSUnderlineStyle.None, // Strikethrough Style
                       null,                  // NSParagraphStyle paragraphStyle = null,
                       0,                     // float strokeWidth = 0,
                       null,                  // NSShadow shadow = null,
                       null,                  // NSUrl link = null,
                       false,                 // bool superscript = false,
                       null,                  // NSTextAttachment attachment = null,
                       NSLigatureType.Default,
                       0,                     // float baselineOffset = 0,
                       0,                     // float kerningAdjustment = 0,
                       0,                     // float obliqueness = 0,
                       0,                     // float expansion = 0,
                       null,                  // NSCursor cursor = null,
                       null,                  // string toolTip = null,
                       0,                     // int characterShape = 0,
                       null,                  // NSGlyphInfo glyphInfo = null,
                       null,                  // NSArray writingDirection = null,
                       false,                 // bool markedClauseSegment = false,
                       NSTextLayoutOrientation.Horizontal,
                       null,                  // NSTextAlternatives textAlternatives = null,
                       NSSpellingState.None));
        }
コード例 #2
0
        private static NSFont ToUIFont(string family, float size, FontAttributes attributes)
        {
            FontExtensions.ToUIFontKey key = new FontExtensions.ToUIFontKey(family, size, attributes);
            Dictionary <FontExtensions.ToUIFontKey, NSFont> dictionary1 = FontExtensions.toUiFont;
            bool lockTaken1 = false;

            try
            {
                Monitor.Enter((object)dictionary1, ref lockTaken1);
                NSFont uiFont;
                if (FontExtensions.toUiFont.TryGetValue(key, out uiFont))
                {
                    return(uiFont);
                }
            }
            finally
            {
                if (lockTaken1)
                {
                    Monitor.Exit((object)dictionary1);
                }
            }
            NSFont uiFont1 = FontExtensions._ToUIFont(family, size, attributes);
            Dictionary <FontExtensions.ToUIFontKey, NSFont> dictionary2 = FontExtensions.toUiFont;
            bool lockTaken2 = false;

            try
            {
                Monitor.Enter((object)dictionary2, ref lockTaken2);
                NSFont uiFont2;
                if (!FontExtensions.toUiFont.TryGetValue(key, out uiFont2))
                {
                    FontExtensions.toUiFont.Add(key, uiFont2 = uiFont1);
                }
                return(uiFont2);
            }
            finally
            {
                if (lockTaken2)
                {
                    Monitor.Exit((object)dictionary2);
                }
            }
        }
コード例 #3
0
        private void UpdateText()
        {
            this.perfectSizeValid = false;

            object[] values = this.Element.GetValues(Label.FormattedTextProperty, Label.TextProperty, Label.TextColorProperty);

            FormattedString formattedString = (FormattedString)values [0];

            if (formattedString != null)
            {
                this.Control.AttributedStringValue = FormattedStringExtensions.ToAttributed(formattedString, (Element)this.Element, (Color)values [2]);
            }
            else
            {
                this.Control.StringValue = (string)values [1];
                this.Control.Font        = FontExtensions.ToUIFont(this.Element);
                this.Control.TextColor   = ColorExtensions.ToUIColor((Color)values [2], ColorExtensions.Black);
            }
            this.Layout();
        }
コード例 #4
0
 private void UpdateFont()
 {
     this.Control.Font = FontExtensions.ToUIFont((IFontElement)this.Element);
 }
コード例 #5
0
 internal static NSFont ToUIFont(this IFontElement element)
 {
     return(FontExtensions.ToUIFont(element.FontFamily, (float)element.FontSize, element.FontAttributes));
 }
コード例 #6
0
 internal static NSFont ToUIFont(this Label label)
 {
     object[] values = label.GetValues(Label.FontFamilyProperty, Label.FontSizeProperty, Label.FontAttributesProperty);
     return(FontExtensions.ToUIFont((string)values [0], (float)(double)values [1], (FontAttributes)values [2]) ??
            NSFont.SystemFontOfSize(NSFont.LabelFontSize));
 }