System.Drawing.Graphics.buildAttributedString C# (CSharp) Method

buildAttributedString() private method

private buildAttributedString ( string text, Font font, StringFormat format = null, Color fontColor = null ) : NSMutableAttributedString
text string
font Font
format StringFormat
fontColor Color
return NSMutableAttributedString
        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)AppKit.NSUnderlineStyle.Single;
                int solid = (int)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)AppKit.NSUnderlineStyle.Single;
                int solid = (int)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;
        }