示例#1
0
 public NSAttributedString(string str,
                           NSFont font                         = null,
                           NSColor foregroundColor             = null,
                           NSColor backgroundColor             = null,
                           NSColor strokeColor                 = null,
                           NSColor underlineColor              = null,
                           NSColor strikethroughColor          = null,
                           NSUnderlineStyle underlineStyle     = NSUnderlineStyle.None,
                           NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None,
                           NSParagraphStyle paragraphStyle     = null,
                           float strokeWidth                   = 0,
                           NSShadow shadow                     = null,
                           NSUrl link                  = null,
                           bool superscript            = false,
                           NSTextAttachment attachment = null,
                           NSLigatureType ligature     = NSLigatureType.Default,
                           float baselineOffset        = 0,
                           float kerningAdjustment     = 0,
                           float obliqueness           = 0,
                           float expansion             = 0,
                           NSCursor cursor             = null,
                           string toolTip              = null,
                           int characterShape          = 0,
                           NSGlyphInfo glyphInfo       = null,
                           NSArray writingDirection    = null,
                           bool markedClauseSegment    = false,
                           NSTextLayoutOrientation verticalGlyphForm = NSTextLayoutOrientation.Horizontal,
                           NSTextAlternatives textAlternatives       = null,
                           NSSpellingState spellingState             = NSSpellingState.None) : this(str, NSStringAttributes.ToDictionary(
                                                                                                        font : font,
                                                                                                        foregroundColor : foregroundColor,
                                                                                                        backgroundColor : backgroundColor,
                                                                                                        strokeColor : strokeColor,
                                                                                                        underlineColor : underlineColor,
                                                                                                        strikethroughColor : strikethroughColor,
                                                                                                        underlineStyle : underlineStyle,
                                                                                                        strikethroughStyle : strikethroughStyle,
                                                                                                        paragraphStyle : paragraphStyle,
                                                                                                        strokeWidth : strokeWidth,
                                                                                                        shadow : shadow,
                                                                                                        link : link,
                                                                                                        superscript : superscript,
                                                                                                        attachment : attachment,
                                                                                                        ligature : ligature,
                                                                                                        baselineOffset : baselineOffset,
                                                                                                        kerningAdjustment : kerningAdjustment,
                                                                                                        obliqueness : obliqueness,
                                                                                                        expansion : expansion,
                                                                                                        cursor : cursor,
                                                                                                        toolTip : toolTip,
                                                                                                        characterShape : characterShape,
                                                                                                        glyphInfo : glyphInfo,
                                                                                                        writingDirection : writingDirection,
                                                                                                        markedClauseSegment : markedClauseSegment,
                                                                                                        verticalGlyphForm : verticalGlyphForm,
                                                                                                        textAlternatives : textAlternatives,
                                                                                                        spellingState : spellingState
                                                                                                        ))
 {
 }
 static AutocompleteExtensions()
 {
     paragraphStyle = new NSMutableParagraphStyle
     {
         MinimumLineHeight = lineHeight,
         MaximumLineHeight = lineHeight
     };
 }
 static TextExtensions()
 {
     paragraphStyle = new NSMutableParagraphStyle
     {
         MinimumLineHeight = 24,
         MaximumLineHeight = 24
     };
 }
示例#4
0
        public void RetainCount()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(6, 0))
            {
                Assert.Inconclusive("Requires iOS 6+");
            }

            var sa = new UIStringAttributes();

            var bc = UIColor.FromRGBA(0.1f, 0.2f, 0.3f, 0.4f);

            Assert.That(bc.RetainCount, Is.EqualTo((nint)2), "BackgroundColor-new");                // bug
            sa.BackgroundColor = bc;
            Assert.That(bc.RetainCount, Is.EqualTo((nint)3), "BackgroundColor-set");

            sa.BaselineOffset = 0.0f;

            var fc = UIColor.FromRGBA(0.5f, 0.6f, 0.7f, 0.8f);

            Assert.That(fc.RetainCount, Is.EqualTo((nint)2), "ForegroundColor-new");                // bug
            sa.ForegroundColor = fc;
            Assert.That(fc.RetainCount, Is.EqualTo((nint)3), "ForegroundColor-set");

            var f       = UIFont.FromName("Helvetica", 12);
            var f_count = f.RetainCount;             // lots of owner

            sa.Font = f;
            Assert.That(f.RetainCount, Is.EqualTo(++f_count), "Font-set");

            var ps = new NSParagraphStyle();

            Assert.That(ps.RetainCount, Is.EqualTo((nint)1), "ParagraphStyle-new");
            sa.ParagraphStyle = ps;
            Assert.That(ps.RetainCount, Is.EqualTo((nint)2), "ParagraphStyle-set");

            for (int i = 0; i < 16; i++)
            {
                Assert.NotNull(sa.BackgroundColor, "BackgroundColor-get");
                Assert.NotNull(sa.ForegroundColor, "ForegroundColor-get");
                Assert.NotNull(sa.Font, "Font-get");
                Assert.NotNull(sa.ParagraphStyle, "ParagraphStyle-get");
            }

            Assert.That(sa.BackgroundColor.RetainCount, Is.EqualTo((nint)3), "BackgroundColor");
            Assert.That(sa.ForegroundColor.RetainCount, Is.EqualTo((nint)3), "ForegroundColor");
            Assert.That(sa.Font.RetainCount, Is.EqualTo(f_count), "Font");
            Assert.That(sa.ParagraphStyle.RetainCount, Is.EqualTo((nint)2), "ParagraphStyle");

            GC.KeepAlive(bc);
            GC.KeepAlive(fc);
            GC.KeepAlive(f);
            GC.KeepAlive(ps);
        }
		static internal NSDictionary ToDictionary (
						  UIFont font,
						  UIColor foregroundColor,
						  UIColor backgroundColor,
						  UIColor strokeColor,
						  NSParagraphStyle paragraphStyle,
						  NSLigatureType ligature,
						  float kerning,
						  NSUnderlineStyle underlineStyle,
						  NSShadow shadow,
						  float strokeWidth,
						  NSUnderlineStyle strikethroughStyle)
		{
			var attr = new UIStringAttributes ();
			if (font != null){
				attr.Font = font;
			}
			if (foregroundColor != null){
				attr.ForegroundColor = foregroundColor;
			}
			if (backgroundColor != null){
				attr.BackgroundColor = backgroundColor;
			}
			if (strokeColor != null){
				attr.StrokeColor = strokeColor;
			}
			if (paragraphStyle != null){
				attr.ParagraphStyle = paragraphStyle;
			}
			if (ligature != NSLigatureType.Default){
				attr.Ligature = ligature;
			}
			if (kerning != 0){
				attr.KerningAdjustment = kerning;
			}
			if (underlineStyle != NSUnderlineStyle.None){
				attr.UnderlineStyle = underlineStyle;
			}
			if (shadow != null){
				attr.Shadow = shadow;
			}
			if (strokeWidth != 0){
				attr.StrokeWidth = strokeWidth;
			}
			if (strikethroughStyle != NSUnderlineStyle.None){
				attr.StrikethroughStyle = strikethroughStyle;
			}
			var dict = attr.Dictionary;
			return dict.Count == 0 ? null : dict;
		}				
 private void ResetAlignment(NSDictionary dic, NSRange range, ref bool stop)
 {
     if (dic.ContainsKey(new NSString("NSParagraphStyle")))
     {
         //set the alignment to the alignment of the label
         NSObject val;
         dic.TryGetValue(new NSString("NSParagraphStyle"), out val);
         NSParagraphStyle style = val as NSParagraphStyle;
         if (style != null)
         {
             style.Alignment = (this.Target as UILabel).TextAlignment;
         }
     }
 }
 public NSMutableAttributedString(string str,
                                  UIFont font                         = null,
                                  UIColor foregroundColor             = null,
                                  UIColor backgroundColor             = null,
                                  UIColor strokeColor                 = null,
                                  NSParagraphStyle paragraphStyle     = null,
                                  NSLigatureType ligatures            = NSLigatureType.Default,
                                  float kerning                       = 0,
                                  NSUnderlineStyle underlineStyle     = NSUnderlineStyle.None,
                                  NSShadow shadow                     = null,
                                  float strokeWidth                   = 0,
                                  NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None)
     : this(str, ToDictionary(font, foregroundColor, backgroundColor, strokeColor, paragraphStyle, ligatures, kerning, underlineStyle, shadow, strokeWidth, strikethroughStyle))
 {
 }
		public NSMutableAttributedString (string str,
						  UIFont font = null,
						  UIColor foregroundColor = null,
						  UIColor backgroundColor = null,
						  UIColor strokeColor = null,
						  NSParagraphStyle paragraphStyle = null,
						  NSLigatureType ligatures = NSLigatureType.Default,
						  float kerning = 0,
						  NSUnderlineStyle underlineStyle = NSUnderlineStyle.None,
						  NSShadow shadow = null,
						  float strokeWidth = 0,
						  NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None)
		: this (str, ToDictionary (font, foregroundColor, backgroundColor, strokeColor, paragraphStyle, ligatures, kerning, underlineStyle, shadow, strokeWidth, strikethroughStyle))
		{
		}
示例#9
0
        static TokenExtensions()
        {
            paragraphStyle = new NSMutableParagraphStyle
            {
                MinimumLineHeight = lineHeight,
                MaximumLineHeight = lineHeight
            };

            tagAttributes = new UIStringAttributes
            {
                Font            = tokenFont,
                ForegroundColor = Color.StartTimeEntry.TokenText.ToNativeColor()
            };

            textVerticalOffset = (lineHeight / 2) - (tokenFont.CapHeight / 2) - 3;
        }
示例#10
0
 protected virtual void DrawCenteredText(CGContext context, String text, float cx, float cy)
 {
     CGPoint cgp = new CGPoint(cx, cy);
     UIFont uif = UIFont.FromName("Arial", 24);
     NSParagraphStyle nsps = new NSParagraphStyle()
     {
         Alignment = UITextAlignment.Center
     };
     //NSAttributedString nsas = new NSAttributedString(str: text,
     //                                                 font: uif,
     //                                                 foregroundColor: UIColor.Red,
     //                                                 paragraphStyle: nsps);
     NSAttributedString nsas = new NSAttributedString(str: text,
                                                      font: uif,
                                                      foregroundColor: UIColor.Red);
     nsas.DrawString(cgp);
 }
示例#11
0
        public static NSAttributedString GetMultiLineAttributedString(string title, string description, nfloat fontSize, NSColor titleColor, NSColor descriptionColor, NSParagraphStyle pstyle = null)
        {
            var result = new NSMutableAttributedString();

            if (!String.IsNullOrEmpty(title))
            {
                result.Append(new NSAttributedString(title, new NSStringAttributes {
                    Font            = NSFont.SystemFontOfSize(fontSize),
                    ForegroundColor = titleColor
                }));
            }

            if (!String.IsNullOrEmpty(description))
            {
                result.Append(NewLine);
                result.Append(new NSAttributedString(description, new NSStringAttributes {
                    Font            = NSFont.SystemFontOfSize(fontSize - 2),
                    ForegroundColor = descriptionColor,
                    ParagraphStyle  = pstyle ?? NSParagraphStyle.DefaultParagraphStyle
                }));
            }

            return(result);
        }
        static internal NSDictionary ToDictionary(
            NSFont font,
            NSColor foregroundColor,
            NSColor backgroundColor,
            NSColor strokeColor,
            NSColor underlineColor,
            NSColor strikethroughColor,
            NSUnderlineStyle underlineStyle,
            NSUnderlineStyle strikethroughStyle,
            NSParagraphStyle paragraphStyle,
            float strokeWidth,
            NSShadow shadow,
            NSUrl link,
            bool superscript,
            NSTextAttachment attachment,
            NSLigatureType ligature,
            float baselineOffset,
            float kerningAdjustment,
            float obliqueness,
            float expansion,
            NSCursor cursor,
            string toolTip,
            int characterShape,
            NSGlyphInfo glyphInfo,
            NSArray writingDirection,
            bool markedClauseSegment,
            NSTextLayoutOrientation verticalGlyphForm,
            NSTextAlternatives textAlternatives,
            NSSpellingState spellingState)
        {
            var attr = new NSStringAttributes();

            if (font != null)
            {
                attr.Font = font;
            }

            if (paragraphStyle != null)
            {
                attr.ParagraphStyle = paragraphStyle;
            }

            if (foregroundColor != null)
            {
                attr.ForegroundColor = foregroundColor;
            }

            if (underlineStyle != NSUnderlineStyle.None)
            {
                attr.UnderlineStyle = (int?)underlineStyle;
            }

            if (superscript)
            {
                attr.Superscript = true;
            }

            if (backgroundColor != null)
            {
                attr.BackgroundColor = backgroundColor;
            }

            if (attachment != null)
            {
                attr.Attachment = attachment;
            }

            if (ligature != NSLigatureType.Default)
            {
                attr.Ligature = ligature;
            }

            if (baselineOffset != 0)
            {
                attr.BaselineOffset = baselineOffset;
            }

            if (kerningAdjustment != 0)
            {
                attr.KerningAdjustment = kerningAdjustment;
            }

            if (link != null)
            {
                attr.Link = link;
            }

            if (strokeWidth != 0)
            {
                attr.StrokeWidth = strokeWidth;
            }

            if (strokeColor != null)
            {
                attr.StrokeColor = strokeColor;
            }

            if (underlineColor != null)
            {
                attr.UnderlineColor = underlineColor;
            }

            if (strikethroughStyle != NSUnderlineStyle.None)
            {
                attr.StrikethroughStyle = (int?)strikethroughStyle;
            }

            if (strikethroughColor != null)
            {
                attr.StrikethroughColor = strikethroughColor;
            }

            if (shadow != null)
            {
                attr.Shadow = shadow;
            }

            if (obliqueness != 0)
            {
                attr.Obliqueness = obliqueness;
            }

            if (expansion != 0)
            {
                attr.Expansion = expansion;
            }

            if (cursor != null)
            {
                attr.Cursor = cursor;
            }

            if (toolTip != null)
            {
                attr.ToolTip = toolTip;
            }

            if (characterShape != 0)
            {
                attr.CharacterShape = 0;
            }

            if (glyphInfo != null)
            {
                attr.GlyphInfo = glyphInfo;
            }

            if (writingDirection != null)
            {
                attr.WritingDirection = writingDirection;
            }

            if (markedClauseSegment)
            {
                attr.MarkedClauseSegment = true;
            }

            if (verticalGlyphForm != NSTextLayoutOrientation.Horizontal)
            {
                attr.VerticalGlyphForm = verticalGlyphForm;
            }

            if (textAlternatives != null)
            {
                attr.TextAlternatives = textAlternatives;
            }

            if (spellingState != NSSpellingState.None)
            {
                attr.SpellingState = spellingState;
            }

            var dict = attr.Dictionary;

            return(dict.Count == 0 ? null : dict);
        }
示例#13
0
        public Theme(bool isDark, double fontScale)
        {
            this.IsDark             = isDark;
            FontScale               = fontScale;
            this.LineHeightMultiple = 1.2f;
            codeFont = Font(FindFontFamily(), (int)(NativeFont.SystemFontSize * fontScale + 0.5));

            defaultParagraph = new NSMutableParagraphStyle {
                LineHeightMultiple = LineHeightMultiple,
            };
            defaultAttrs = new NativeStringAttributes {
                Font            = codeFont,
                ForegroundColor = !isDark?Rgb(101, 121, 140) : Rgb(127, 140, 152),
                                      ParagraphStyle = defaultParagraph,
            }.Dictionary;
            SelectedAttributes = new NativeStringAttributes {
#if __MACOS__
                BackgroundColor = !isDark ? NativeColor.SelectedTextBackground : NativeColor.SelectedTextBackground.ColorWithAlphaComponent(0.5f),
#elif __IOS__
                BackgroundColor = Rgb(0, 0x84, 0xD1).ColorWithAlpha(0.5f),
#endif
            }.Dictionary;

            BackgroundColor = !isDark?Rgb(0xFF, 0xFF, 0xFF) : Rgb(41, 42, 47);

            ErrorBubbleBackgroundColor = !isDark?Rgb(0xC5, 0, 0xB) : Rgb(0xC5 * 5 / 8, 0, 0xB);

            ErrorBubbleTextAttributes = new NativeStringAttributes {
                ForegroundColor = Gray(255).ColorWithAlphaComponent(0.9375f),
                Font            = NativeFont.BoldSystemFontOfSize((nfloat)(NativeFont.SystemFontSize)),
                ParagraphStyle  = new NSMutableParagraphStyle {
#if __MACOS__
                    LineBreakMode = NativeLineBreakMode.ByWordWrapping,
#elif __IOS__
                    LineBreakMode = NativeLineBreakMode.WordWrap,
#endif
                },
            }.Dictionary;
            LineNumberFont  = Font(codeFont.GetFontName(), (int)(NativeFont.SystemFontSize * 0.8 * fontScale + 0.5));
            LineNumberColor = !isDark?Gray(0).ColorWithAlphaComponent(0.25f) : Gray(255).ColorWithAlphaComponent(0.125f);

            LineNumberAttributes = MakeLineNumberAttrs();
            ColorAttributes      = Enumerable.Repeat(defaultAttrs, 16).ToArray();

            // Xcode Colors
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Number]     = MakeAttrs(Rgb(38, 42, 215), Rgb(166, 157, 247));
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.String]     = MakeAttrs(Rgb(197, 0, 11), Rgb(255, 128, 112));
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Identifier] = MakeAttrs(Gray(0x33), Gray(0xE0));
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Operator]   = MakeAttrs(Gray(0x88), Gray(0xAA));
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Keyword]    = MakeAttrs(Rgb(173, 61, 164), Rgb(255, 122, 178));
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Type]       = MakeAttrs(Rgb(0, 128, 128), Rgb(0, 192, 164));
            ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Function]   = MakeAttrs(Rgb(204, 102, 0), Rgb(255, 161, 79));

            // Arduino Colors
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Number] = MakeAttrs (Rgb (197, 0, 11), Rgb (255, 211, 32));
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.String] = MakeAttrs (Rgb (197, 0, 11), Rgb (255, 211, 32));
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Identifier] = MakeAttrs (NativeColor.Black, NativeColor.White);
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Keyword] = MakeAttrs (Rgb (52, 120, 184), Rgb (52, 120, 184));
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Type] = MakeAttrs (Rgb (0, 128, 128), Rgb (0, 164, 164));
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Function] = MakeAttrs (Rgb (204, 102, 0), Rgb (204, 102, 0));
            //ColorAttributes[(int)CLanguage.Syntax.SyntaxColor.Operator] = MakeAttrs (Rgb (96, 96, 96), Rgb (164, 164, 192));
        }
示例#14
0
        static internal NSDictionary ToDictionary(
            UIFont font,
            UIColor foregroundColor,
            UIColor backgroundColor,
            UIColor strokeColor,
            NSParagraphStyle paragraphStyle,
            NSLigatureType ligature,
            float kerning,
            NSUnderlineStyle underlineStyle,
#if !WATCH
            NSShadow shadow,
#endif
            float strokeWidth,
            NSUnderlineStyle strikethroughStyle)
        {
            var attr = new UIStringAttributes();

            if (font != null)
            {
                attr.Font = font;
            }
            if (foregroundColor != null)
            {
                attr.ForegroundColor = foregroundColor;
            }
            if (backgroundColor != null)
            {
                attr.BackgroundColor = backgroundColor;
            }
            if (strokeColor != null)
            {
                attr.StrokeColor = strokeColor;
            }
            if (paragraphStyle != null)
            {
                attr.ParagraphStyle = paragraphStyle;
            }
            if (ligature != NSLigatureType.Default)
            {
                attr.Ligature = ligature;
            }
            if (kerning != 0)
            {
                attr.KerningAdjustment = kerning;
            }
            if (underlineStyle != NSUnderlineStyle.None)
            {
                attr.UnderlineStyle = underlineStyle;
            }
#if !WATCH
            if (shadow != null)
            {
                attr.Shadow = shadow;
            }
#endif
            if (strokeWidth != 0)
            {
                attr.StrokeWidth = strokeWidth;
            }
            if (strikethroughStyle != NSUnderlineStyle.None)
            {
                attr.StrikethroughStyle = strikethroughStyle;
            }
            var dict = attr.Dictionary;
            return(dict.Count == 0 ? null : dict);
        }
示例#15
0
        public NSAttributedString(string str,
            NSFont font = null,
            NSColor foregroundColor = null,
            NSColor backgroundColor = null,
            NSColor strokeColor = null,
            NSColor underlineColor = null,
            NSColor strikethroughColor = null,
            NSUnderlineStyle underlineStyle = NSUnderlineStyle.None,
            NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None,
            NSParagraphStyle paragraphStyle = null,
            float strokeWidth = 0,
            NSShadow shadow = null,
            NSUrl link = null,
            bool superscript = false,
            NSTextAttachment attachment = null,
            NSLigatureType ligature = NSLigatureType.Default,
            float baselineOffset = 0,
            float kerningAdjustment = 0,
            float obliqueness = 0,
            float expansion = 0,
            NSCursor cursor = null,
            string toolTip = null,
            int characterShape = 0,
            NSGlyphInfo glyphInfo = null,
            NSArray writingDirection = null,
            bool markedClauseSegment = false,
            NSTextLayoutOrientation verticalGlyphForm = NSTextLayoutOrientation.Horizontal,
            NSTextAlternatives textAlternatives = null,
            NSSpellingState spellingState = NSSpellingState.None)
            : this(str, NSStringAttributes.ToDictionary (
				font: font,
				foregroundColor: foregroundColor,
				backgroundColor: backgroundColor,
				strokeColor: strokeColor,
				underlineColor: underlineColor,
				strikethroughColor: strikethroughColor,
				underlineStyle: underlineStyle,
				strikethroughStyle: strikethroughStyle,
				paragraphStyle: paragraphStyle,
				strokeWidth: strokeWidth,
				shadow: shadow,
				link: link,
				superscript: superscript,
				attachment: attachment,
				ligature: ligature,
				baselineOffset: baselineOffset,
				kerningAdjustment: kerningAdjustment,
				obliqueness: obliqueness,
				expansion: expansion,
				cursor: cursor,
				toolTip: toolTip,
				characterShape: characterShape,
				glyphInfo: glyphInfo,
				writingDirection: writingDirection,
				markedClauseSegment: markedClauseSegment,
				verticalGlyphForm: verticalGlyphForm,
				textAlternatives: textAlternatives,
				spellingState: spellingState
			))
        {
        }
示例#16
0
        public static NSAttributedString GetAttributedString(string text, NSFont font = null, NSColor foregroundColor = null, NSColor backgroundColor = null, NSParagraphStyle paragraphStyle = default(NSParagraphStyle))
        {
            //There is no need create NSStringAttributes element
            if (font == null && foregroundColor == null && backgroundColor == null && paragraphStyle == default(NSParagraphStyle))
            {
                return(new NSAttributedString(text));
            }
            var attributed = new NSAttributedString(text, new NSStringAttributes
            {
                Font            = font,
                BackgroundColor = backgroundColor,
                ForegroundColor = foregroundColor,
                ParagraphStyle  = paragraphStyle
            });

            return(attributed);
        }