コード例 #1
0
        private static NSMutableAttributedString buildAttributedString(string text, Font font, 
		                                                        Color? fontColor=null)
        {
            // Create a new attributed string definition
            var ctAttributes = new CTStringAttributes ();

            // Font attribute
            ctAttributes.Font = font.nativeFont;
            // -- end font

            if (fontColor.HasValue) {

                // Font color
                var fc = fontColor.Value;
                var cgColor = new CGColor(fc.R / 255f,
                                          fc.G / 255f,
                                          fc.B / 255f,
                                          fc.A / 255f);

                ctAttributes.ForegroundColor = cgColor;
                ctAttributes.ForegroundColorFromContext = false;
                // -- end font Color
            }

            if (font.Underline) {
                // Underline
            #if MONOMAC
                int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                var attss = single | solid;
                ctAttributes.UnderlineStyleValue = attss;
            #else
                ctAttributes.UnderlineStyleValue = 1;
            #endif
                // --- end underline
            }

            if (font.Strikeout) {
                // StrikeThrough
                //				NSColor bcolor = NSColor.Blue;
                //				NSObject bcolorObject = new NSObject(bcolor.Handle);
                //				attsDic.Add(NSAttributedString.StrikethroughColorAttributeName, bcolorObject);
                //				#if MACOS
                //				int stsingle = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                //				int stsolid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                //				var stattss = stsingle | stsolid;
                //				var stunderlineObject = NSNumber.FromInt32(stattss);
                //				#else
                //				var stunderlineObject = NSNumber.FromInt32 (1);
                //				#endif
                //
                //				attsDic.Add(StrikethroughStyleAttributeName, stunderlineObject);
                // --- end underline
            }

            // Text alignment
            var alignment = CTTextAlignment.Left;
            var alignmentSettings = new CTParagraphStyleSettings();
            alignmentSettings.Alignment = alignment;
            var paragraphStyle = new CTParagraphStyle(alignmentSettings);

            ctAttributes.ParagraphStyle = paragraphStyle;
            // end text alignment

            NSMutableAttributedString atts =
                new NSMutableAttributedString(text,ctAttributes.Dictionary);

            return atts;
        }
コード例 #2
0
        private NSMutableAttributedString buildAttributedString(string text, Font font, StringFormat format = null, 
			Color? fontColor=null)
        {
            // Create a new attributed string definition
            var ctAttributes = new CTStringAttributes ();

            // Font attribute
            ctAttributes.Font = font.nativeFont;
            // -- end font

            if (format != null && (format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                //ctAttributes.VerticalForms = true;

            }

            if (fontColor.HasValue) {

                // Font color
                var fc = fontColor.Value;
                var cgColor = new CGColor(fc.R / 255f,
                    fc.G / 255f,
                    fc.B / 255f,
                    fc.A / 255f);

                ctAttributes.ForegroundColor = cgColor;
                ctAttributes.ForegroundColorFromContext = false;
                // -- end font Color
            }

            if (font.Underline) {
                // Underline
            #if MONOMAC
                int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                var attss = single | solid;
                ctAttributes.UnderlineStyleValue = attss;
            #else
                ctAttributes.UnderlineStyleValue = 1;
            #endif
                // --- end underline
            }

            if (font.Strikeout) {
                // StrikeThrough
            #if MONOMAC
                int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                var attss = single | solid;
                ctAttributes.UnderlineStyleValue = attss;
            #else
                ctAttributes.UnderlineStyleValue = 1;
            #endif

                // --- end StrikeThrough
            }

            var alignment = CTTextAlignment.Left;
            var alignmentSettings = new CTParagraphStyleSettings();
            alignmentSettings.Alignment = alignment;
            var paragraphStyle = new CTParagraphStyle(alignmentSettings);

            ctAttributes.ParagraphStyle = paragraphStyle;
            // end text alignment

            NSMutableAttributedString atts =
                new NSMutableAttributedString(text,ctAttributes.Dictionary);

            return atts;
        }
コード例 #3
0
ファイル: MacControlExtensions.cs プロジェクト: mhusen/Eto
		public static NSAttributedString ToAttributedStringWithMnemonic(this string value, NSDictionary attributes = null)
		{
			if (value == null)
				return null;
			var match = Regex.Match(value, @"(?<=([^&](?:[&]{2})*)|^)[&](?![&])");
			if (match.Success)
			{
				value = value.Remove(match.Index, 1);
				value = value.Replace("&&", "&");
				var str = attributes != null ? new NSMutableAttributedString(value, attributes) : new NSMutableAttributedString(value);
				var attr = new CTStringAttributes();
				attr.UnderlineStyle = CTUnderlineStyle.Single;
				str.AddAttributes(attr, new NSRange(match.Index, 1));
				return str;
			}
			else
			{
				value = value.Replace("&&", "&");
				return attributes != null ? new NSAttributedString(value, attributes) : new NSAttributedString(value);
			}
		}
コード例 #4
0
 public void SetAttributes(CTStringAttributes attrs, NSRange range)
 {
     SetAttributes (attrs == null ? null : attrs.Dictionary, range);
 }
コード例 #5
0
 public NSMutableAttributedString(string str, CTStringAttributes attributes)
     : this(str, attributes == null ? null : attributes.Dictionary)
 {
 }
コード例 #6
0
		public NSAttributedString (string str, CTStringAttributes attributes)
			: this (str, attributes != null ? attributes.Dictionary : null)
		{
		}