Exemple #1
0
        protected override void Write(AttributedTextRenderer renderer, HtmlInline obj)
        {
            var tag = obj.Tag;

            if (tag.StartsWith("<span ", StringComparison.Ordinal) &&
                !tag.EndsWith("/>", StringComparison.Ordinal))
            {
                var styleIndex = tag.IndexOf("style", StringComparison.Ordinal);
                if (styleIndex >= 0)
                {
                    var firstQuote = tag.IndexOf('"', styleIndex);
                    if (firstQuote > styleIndex)
                    {
                        firstQuote += 1;
                        var secondQuote = tag.IndexOf('"', firstQuote);
                        if (secondQuote > firstQuote)
                        {
                            var style    = tag.Substring(firstQuote, secondQuote - firstQuote);
                            var start    = renderer.Count;
                            var spanData = new SpanData {
                                Start = start, Style = style
                            };
                            _spans.Push(spanData);
                        }
                    }
                }
            }
            else if (tag.Equals("</span>", StringComparison.Ordinal))
            {
                if (_spans.Count > 0)
                {
                    var span   = _spans.Pop();
                    var end    = renderer.Count;
                    var length = end - span.Start;

                    var values = SimpleCssParser.Parse(span.Style);
                    if (values != null)
                    {
                        var attributes = new TextAttributes();

                        string color = null;
                        if (values.TryGetValue("color", out color))
                        {
                            attributes[TextAttribute.Color] = color;
                        }

                        string background = null;
                        if (values.TryGetValue("background", out background))
                        {
                            attributes[TextAttribute.Background] = background;
                        }

                        if (attributes.Count > 0)
                        {
                            renderer.AddTextRun(span.Start, length, attributes);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void ReadRun()
        {
            TextAttributes attributes = new TextAttributes();

            var start  = ReadInt(XmlNames.Start, 0);
            var length = ReadInt(XmlNames.Length, 0);

            if (_reader.HasAttributes)
            {
                _reader.MoveToElement();
                while (_reader.MoveToNextAttribute())
                {
                    var attributeName  = _reader.Name;
                    var attributeValue = _reader.Value;

                    if (!(XmlNames.Start.Equals(attributeName) || XmlNames.Length.Equals(attributeName)))
                    {
                        if (Enum.TryParse(attributeName, out TextAttribute key))
                        {
                            attributes[key] = attributeValue;
                        }
                    }
                }

                _reader.MoveToElement();
            }

            var run = new AttributedTextRun(start, length, attributes);

            _runs.Add(run);
        }
        protected override void Write(AttributedTextRenderer renderer, EmphasisInline obj)
        {
            var start = renderer.Count;

            renderer.WriteChildren(obj);
            var length = renderer.Count - start;

            var bold          = IsBold(obj);
            var underline     = IsUnderline(obj);
            var italic        = IsItalic(obj);
            var strikethrough = IsStrikethrough(obj);
            var subscript     = IsSubscript(obj);
            var superscript   = IsSuperscript(obj);

            if (length > 0 && (bold || italic || strikethrough || subscript || superscript || underline))
            {
                var attributes = new TextAttributes();
                attributes.SetBold(bold);
                attributes.SetItalic(italic);
                attributes.SetStrikethrough(strikethrough);
                attributes.SetSubscript(subscript);
                attributes.SetSuperscript(superscript);
                attributes.SetUnderline(underline);
                renderer.AddTextRun(start, length, attributes);
            }
        }
        protected override void Write(
            AttributedTextRenderer renderer,
            ListBlock listBlock)
        {
            var start = renderer.Count;

            renderer.EnsureLine();

            foreach (var item in listBlock)
            {
                var listItem = (ListItemBlock)item;

                renderer.EnsureLine();
                renderer.Write("• ");
                renderer.WriteChildren(listItem);
            }

            var length = renderer.Count - start;

            if (length > 0)
            {
                var attributes = new TextAttributes();
                if (!listBlock.IsOrdered)
                {
                    attributes[TextAttribute.UnorderedList] = "True";
                }
                renderer.AddTextRun(start, length, attributes);
            }
        }
Exemple #5
0
        public override Brush GetSymbolBrush(IBioSymbol symbol)
        {
            TextAttributes ta = new TextAttributes();

            _options.GetAttributes(symbol, ref ta);
            return(ta.Foreground);
        }
 public static dynamic GetTSObject(TextAttributes dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Exemple #7
0
        public override Color GetSymbolColor(IBioSymbol symbol)
        {
            TextAttributes ta = new TextAttributes();

            _options.GetAttributes(symbol, ref ta);
            if (ta.Foreground is SolidColorBrush)
            {
                SolidColorBrush scb = (SolidColorBrush)ta.Foreground;
                return(scb.Color);
            }
            return(Colors.Black);
        }
Exemple #8
0
        public override TextAttributes GetSequenceAttributes(IList <IBioSymbol> symbols, int start, out bool canMergeDuplicates)
        {
            TextAttributes defaultAttributes = new TextAttributes();
            IBioSymbol     symbol            = symbols[start];

            canMergeDuplicates = true;

            if (_mainVm.SelectedReferenceSequences.Count > 0 &&
                symbol.Type != BioSymbolType.None && symbol.Type != BioSymbolType.Missing)
            {
                if (_mainVm.SelectedReferenceSequences.Where(rs => rs.AlignedData == symbols).FirstOrDefault() == null)
                {
                    canMergeDuplicates = false;
                    var rs = _mainVm.SelectedReferenceSequences.FirstOrDefault(seq => seq.AlignedData[start].Value == symbol.Value);
                    if (rs != null)
                    {
                        defaultAttributes.Background = rs.ReferenceSequenceColor;
                    }
                }
            }

            _options.GetAttributes(symbol, ref defaultAttributes);
            return(defaultAttributes);
        }
        /// <summary>
        /// Gets a data form containing editable parameters from an object.
        /// </summary>
        /// <param name="Client">Client</param>
        /// <param name="e">IQ Event Arguments describing the request.</param>
        /// <param name="EditableObject">Object whose parameters will be edited.</param>
        /// <param name="Title">Title of form.</param>
        /// <returns>Data form containing editable parameters.</returns>
        public static async Task <DataForm> GetEditableForm(XmppClient Client, IqEventArgs e, object EditableObject, string Title)
        {
            Type     T = EditableObject.GetType();
            string   DefaultLanguageCode = GetDefaultLanguageCode(T);
            DataForm Parameters          = new DataForm(Client, FormType.Form, e.To, e.From);
            Language Language            = await ConcentratorServer.GetLanguage(e.Query, DefaultLanguageCode);

            Namespace    Namespace = null;
            List <Field> Fields    = new List <Field>();
            List <Page>  Pages     = new List <Page>();
            Dictionary <string, Page>             PageByLabel = new Dictionary <string, Page>();
            Dictionary <string, Section>          SectionByPageAndSectionLabel = null;
            List <KeyValuePair <string, string> > Options = null;
            string                     NamespaceStr;
            string                     LastNamespaceStr = null;
            string                     Header;
            string                     ToolTip;
            string                     PageLabel;
            string                     SectionLabel;
            string                     s;
            int                        StringId;
            int                        PagePriority;
            int                        PageOrdinal = 0;
            int                        FieldPriority;
            int                        FieldOrdinal = 0;
            bool                       Required;
            bool                       ReadOnly;
            bool                       Masked;
            bool                       Alpha;
            bool                       DateOnly;
            bool                       Nullable;
            HeaderAttribute            HeaderAttribute;
            ToolTipAttribute           ToolTipAttribute;
            PageAttribute              PageAttribute;
            SectionAttribute           SectionAttribute;
            OptionAttribute            OptionAttribute;
            TextAttribute              TextAttribute;
            RegularExpressionAttribute RegularExpressionAttribute;
            LinkedList <TextAttribute> TextAttributes;
            RangeAttribute             RangeAttribute;
            ValidationMethod           ValidationMethod;
            Type                       PropertyType;
            Field                      Field;
            Page                       DefaultPage = null;
            Page                       Page;

            if (Namespace is null)
            {
                Namespace = await Language.CreateNamespaceAsync(T.Namespace);
            }

            LinkedList <KeyValuePair <PropertyInfo, FieldInfo> > Properties = new LinkedList <KeyValuePair <PropertyInfo, FieldInfo> >();

            foreach (PropertyInfo PI in T.GetRuntimeProperties())
            {
                if (PI.CanRead)
                {
                    Properties.AddLast(new KeyValuePair <PropertyInfo, FieldInfo>(PI, null));
                }
            }

            foreach (FieldInfo FI in T.GetRuntimeFields())
            {
                Properties.AddLast(new KeyValuePair <PropertyInfo, FieldInfo>(null, FI));
            }

            foreach (KeyValuePair <PropertyInfo, FieldInfo> Rec in Properties)
            {
                PropertyInfo PropertyInfo = Rec.Key;
                FieldInfo    FieldInfo    = Rec.Value;

                NamespaceStr = (PropertyInfo?.DeclaringType ?? FieldInfo.DeclaringType).Namespace;
                if (Namespace is null || NamespaceStr != LastNamespaceStr)
                {
                    Namespace = await Language.GetNamespaceAsync(NamespaceStr);

                    LastNamespaceStr = NamespaceStr;
                }

                Header           = ToolTip = PageLabel = SectionLabel = null;
                TextAttributes   = null;
                ValidationMethod = null;
                Options          = null;
                Required         = Masked = Alpha = DateOnly = false;
                ReadOnly         = PropertyInfo != null && !PropertyInfo.CanWrite;
                PagePriority     = PageAttribute.DefaultPriority;
                FieldPriority    = HeaderAttribute.DefaultPriority;

                foreach (Attribute Attr in (PropertyInfo?.GetCustomAttributes() ?? FieldInfo.GetCustomAttributes()))
                {
                    if ((HeaderAttribute = Attr as HeaderAttribute) != null)
                    {
                        Header        = HeaderAttribute.Header;
                        StringId      = HeaderAttribute.StringId;
                        FieldPriority = HeaderAttribute.Priority;
                        if (StringId > 0)
                        {
                            Header = await Namespace.GetStringAsync(StringId, Header);
                        }
                    }
                    else if ((ToolTipAttribute = Attr as ToolTipAttribute) != null)
                    {
                        ToolTip  = ToolTipAttribute.ToolTip;
                        StringId = ToolTipAttribute.StringId;
                        if (StringId > 0)
                        {
                            ToolTip = await Namespace.GetStringAsync(StringId, ToolTip);
                        }
                    }
                    else if ((PageAttribute = Attr as PageAttribute) != null)
                    {
                        PageLabel    = PageAttribute.Label;
                        StringId     = PageAttribute.StringId;
                        PagePriority = PageAttribute.Priority;
                        if (StringId > 0)
                        {
                            PageLabel = await Namespace.GetStringAsync(StringId, PageLabel);
                        }
                    }
                    else if ((SectionAttribute = Attr as SectionAttribute) != null)
                    {
                        SectionLabel = SectionAttribute.Label;
                        StringId     = SectionAttribute.StringId;
                        if (StringId > 0)
                        {
                            SectionLabel = await Namespace.GetStringAsync(StringId, SectionLabel);
                        }
                    }
                    else if ((TextAttribute = Attr as TextAttribute) != null)
                    {
                        if (TextAttributes is null)
                        {
                            TextAttributes = new LinkedList <TextAttribute>();
                        }

                        TextAttributes.AddLast(TextAttribute);
                    }
                    else if ((OptionAttribute = Attr as OptionAttribute) != null)
                    {
                        if (Options is null)
                        {
                            Options = new List <KeyValuePair <string, string> >();
                        }

                        StringId = OptionAttribute.StringId;
                        if (StringId > 0)
                        {
                            Options.Add(new KeyValuePair <string, string>(OptionAttribute.Option.ToString(),
                                                                          await Namespace.GetStringAsync(StringId, OptionAttribute.Label)));
                        }
                        else
                        {
                            Options.Add(new KeyValuePair <string, string>(OptionAttribute.Option.ToString(), OptionAttribute.Label));
                        }
                    }
                    else if ((RegularExpressionAttribute = Attr as RegularExpressionAttribute) != null)
                    {
                        ValidationMethod = new RegexValidation(RegularExpressionAttribute.Pattern);
                    }
                    else if ((RangeAttribute = Attr as RangeAttribute) != null)
                    {
                        ValidationMethod = new RangeValidation(RangeAttribute.Min, RangeAttribute.Max);
                    }
                    else if (Attr is OpenAttribute)
                    {
                        ValidationMethod = new OpenValidation();
                    }
                    else if (Attr is RequiredAttribute)
                    {
                        Required = true;
                    }
                    else if (Attr is ReadOnlyAttribute)
                    {
                        ReadOnly = true;
                    }
                    else if (Attr is MaskedAttribute)
                    {
                        Masked = true;
                    }
                    else if (Attr is AlphaChannelAttribute)
                    {
                        Alpha = true;
                    }
                    else if (Attr is DateOnlyAttribute)
                    {
                        DateOnly = true;
                    }
                }

                if (Header is null)
                {
                    continue;
                }

                PropertyType = PropertyInfo?.PropertyType ?? FieldInfo.FieldType;
                Field        = null;
                Nullable     = false;

                if (PropertyType.GetTypeInfo().IsGenericType)
                {
                    Type GT = PropertyType.GetGenericTypeDefinition();
                    if (GT == typeof(Nullable <>))
                    {
                        Nullable     = true;
                        PropertyType = PropertyType.GenericTypeArguments[0];
                    }
                }

                string PropertyName  = PropertyInfo?.Name ?? FieldInfo.Name;
                object PropertyValue = (PropertyInfo?.GetValue(EditableObject) ?? FieldInfo.GetValue(EditableObject));

                if (PropertyType == typeof(string[]))
                {
                    if (ValidationMethod is null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    if (Options is null)
                    {
                        Field = new TextMultiField(Parameters, PropertyName, Header, Required, (string[])PropertyValue,
                                                   null, ToolTip, StringDataType.Instance, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                    else
                    {
                        Field = new ListMultiField(Parameters, PropertyName, Header, Required, (string[])PropertyValue,
                                                   Options.ToArray(), ToolTip, StringDataType.Instance, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                }
                else if (PropertyType.GetTypeInfo().IsEnum)
                {
                    if (ValidationMethod is null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    if (Options is null)
                    {
                        Options = new List <KeyValuePair <string, string> >();

                        foreach (string Option in Enum.GetNames(PropertyType))
                        {
                            Options.Add(new KeyValuePair <string, string>(Option, Option));
                        }
                    }

                    s = PropertyValue?.ToString();
                    if (Nullable && s is null)
                    {
                        s = string.Empty;
                    }

                    Field = new ListSingleField(Parameters, PropertyName, Header, Required, new string[] { s },
                                                Options.ToArray(), ToolTip, null, ValidationMethod, string.Empty, false, ReadOnly, false);
                }
                else if (PropertyType == typeof(bool))
                {
                    if (ValidationMethod is null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    if (Nullable && PropertyValue is null)
                    {
                        s = string.Empty;
                    }
                    else
                    {
                        s = CommonTypes.Encode((bool)PropertyValue);
                    }

                    Field = new BooleanField(Parameters, PropertyName, Header, Required, new string[] { s },
                                             Options?.ToArray(), ToolTip, BooleanDataType.Instance, ValidationMethod,
                                             string.Empty, false, ReadOnly, false);
                }
                else
                {
                    DataType DataType;

                    if (PropertyType == typeof(string))
                    {
                        DataType = StringDataType.Instance;
                    }
                    else if (PropertyType == typeof(sbyte))
                    {
                        DataType = ByteDataType.Instance;
                    }
                    else if (PropertyType == typeof(short))
                    {
                        DataType = ShortDataType.Instance;
                    }
                    else if (PropertyType == typeof(int))
                    {
                        DataType = IntDataType.Instance;
                    }
                    else if (PropertyType == typeof(long))
                    {
                        DataType = LongDataType.Instance;
                    }
                    else if (PropertyType == typeof(byte))
                    {
                        DataType = ShortDataType.Instance;

                        if (ValidationMethod is null)
                        {
                            ValidationMethod = new RangeValidation(byte.MinValue.ToString(), byte.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(ushort))
                    {
                        DataType = IntDataType.Instance;

                        if (ValidationMethod is null)
                        {
                            ValidationMethod = new RangeValidation(ushort.MinValue.ToString(), ushort.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(uint))
                    {
                        DataType = LongDataType.Instance;

                        if (ValidationMethod is null)
                        {
                            ValidationMethod = new RangeValidation(uint.MinValue.ToString(), uint.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(ulong))
                    {
                        DataType = IntegerDataType.Instance;

                        if (ValidationMethod is null)
                        {
                            ValidationMethod = new RangeValidation(ulong.MinValue.ToString(), ulong.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(DateTime))
                    {
                        if (DateOnly)
                        {
                            DataType = DateDataType.Instance;
                        }
                        else
                        {
                            DataType = DateTimeDataType.Instance;
                        }
                    }
                    else if (PropertyType == typeof(decimal))
                    {
                        DataType = DecimalDataType.Instance;
                    }
                    else if (PropertyType == typeof(double))
                    {
                        DataType = DoubleDataType.Instance;
                    }
                    else if (PropertyType == typeof(float))
                    {
                        DataType = DoubleDataType.Instance;                            // Use xs:double anyway
                    }
                    else if (PropertyType == typeof(TimeSpan))
                    {
                        DataType = TimeDataType.Instance;
                    }
                    else if (PropertyType == typeof(Uri))
                    {
                        DataType = AnyUriDataType.Instance;
                    }
                    else if (PropertyType == typeof(SKColor))
                    {
                        if (Alpha)
                        {
                            DataType = ColorAlphaDataType.Instance;
                        }
                        else
                        {
                            DataType = ColorDataType.Instance;
                        }
                    }
                    else
                    {
                        DataType = StringDataType.Instance;
                    }

                    if (ValidationMethod is null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    s = PropertyValue?.ToString();
                    if (Nullable && s is null)
                    {
                        s = string.Empty;
                    }

                    if (Masked)
                    {
                        Field = new TextPrivateField(Parameters, PropertyName, Header, Required, new string[] { s },
                                                     Options?.ToArray(), ToolTip, DataType, ValidationMethod,
                                                     string.Empty, false, ReadOnly, false);
                    }
                    else if (Options is null)
                    {
                        Field = new TextSingleField(Parameters, PropertyName, Header, Required, new string[] { s },
                                                    null, ToolTip, DataType, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                    else
                    {
                        Field = new ListSingleField(Parameters, PropertyName, Header, Required, new string[] { s },
                                                    Options.ToArray(), ToolTip, DataType, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                }

                if (Field is null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(PageLabel))
                {
                    if (DefaultPage is null)
                    {
                        DefaultPage = new Page(Parameters, string.Empty)
                        {
                            Priority = PageAttribute.DefaultPriority,
                            Ordinal  = PageOrdinal++
                        };
                        Pages.Add(DefaultPage);
                        PageByLabel[string.Empty] = DefaultPage;
                    }

                    Page      = DefaultPage;
                    PageLabel = string.Empty;
                }
                else
                {
                    if (!PageByLabel.TryGetValue(PageLabel, out Page))
                    {
                        Page = new Page(Parameters, PageLabel)
                        {
                            Priority = PagePriority,
                            Ordinal  = PageOrdinal++
                        };
                        Pages.Add(Page);
                        PageByLabel[PageLabel] = Page;
                    }
                }

                Field.Priority = FieldPriority;
                Field.Ordinal  = FieldOrdinal++;
                Fields.Add(Field);

                if (string.IsNullOrEmpty(SectionLabel))
                {
                    if (TextAttributes != null)
                    {
                        foreach (TextAttribute TextAttr in TextAttributes)
                        {
                            if (TextAttr.Position == TextPosition.BeforeField)
                            {
                                StringId = TextAttr.StringId;
                                if (StringId > 0)
                                {
                                    Page.Add(new TextElement(Parameters, await Namespace.GetStringAsync(StringId, TextAttr.Label)));
                                }
                                else
                                {
                                    Page.Add(new TextElement(Parameters, TextAttr.Label));
                                }
                            }
                        }
                    }

                    Page.Add(new FieldReference(Parameters, Field.Var));

                    if (TextAttributes != null)
                    {
                        foreach (TextAttribute TextAttr in TextAttributes)
                        {
                            if (TextAttr.Position == TextPosition.AfterField)
                            {
                                StringId = TextAttr.StringId;
                                if (StringId > 0)
                                {
                                    Page.Add(new TextElement(Parameters, await Namespace.GetStringAsync(StringId, TextAttr.Label)));
                                }
                                else
                                {
                                    Page.Add(new TextElement(Parameters, TextAttr.Label));
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (SectionByPageAndSectionLabel is null)
                    {
                        SectionByPageAndSectionLabel = new Dictionary <string, Section>();
                    }

                    s = PageLabel + " \xa0 " + SectionLabel;
                    if (!SectionByPageAndSectionLabel.TryGetValue(s, out Section Section))
                    {
                        Section = new Section(Parameters, SectionLabel);
                        SectionByPageAndSectionLabel[s] = Section;

                        Page.Add(Section);
                    }

                    if (TextAttributes != null)
                    {
                        foreach (TextAttribute TextAttr in TextAttributes)
                        {
                            if (TextAttr.Position == TextPosition.BeforeField)
                            {
                                StringId = TextAttr.StringId;
                                if (StringId > 0)
                                {
                                    Section.Add(new TextElement(Parameters, await Namespace.GetStringAsync(StringId, TextAttr.Label)));
                                }
                                else
                                {
                                    Section.Add(new TextElement(Parameters, TextAttr.Label));
                                }
                            }
                        }
                    }

                    Section.Add(new FieldReference(Parameters, Field.Var));

                    if (TextAttributes != null)
                    {
                        foreach (TextAttribute TextAttr in TextAttributes)
                        {
                            if (TextAttr.Position == TextPosition.AfterField)
                            {
                                StringId = TextAttr.StringId;
                                if (StringId > 0)
                                {
                                    Section.Add(new TextElement(Parameters, await Namespace.GetStringAsync(StringId, TextAttr.Label)));
                                }
                                else
                                {
                                    Section.Add(new TextElement(Parameters, TextAttr.Label));
                                }
                            }
                        }
                    }
                }
            }

            if (EditableObject is IPropertyFormAnnotation PropertyFormAnnotation)
            {
                FormState State = new FormState()
                {
                    Form        = Parameters,
                    PageByLabel = PageByLabel,
                    SectionByPageAndSectionLabel = SectionByPageAndSectionLabel,
                    DefaultPage  = DefaultPage,
                    LanguageCode = Language.Code,
                    Fields       = Fields,
                    Pages        = Pages,
                    FieldOrdinal = FieldOrdinal,
                    PageOrdinal  = PageOrdinal
                };

                await PropertyFormAnnotation.AnnotatePropertyForm(State);
            }

            Fields.Sort(OrderFields);
            Parameters.Title  = Title;
            Parameters.Fields = Fields.ToArray();

            if (Pages != null)
            {
                Pages.Sort(OrderPages);

                foreach (Page Page2 in Pages)
                {
                    Page2.Sort();
                }
            }

            Parameters.Pages = Pages.ToArray();

            return(Parameters);
        }
Exemple #10
0
        /// <summary>
        /// Gets a data form containing editable parameters from an object.
        /// </summary>
        /// <param name="Client">Client</param>
        /// <param name="e">IQ Event Arguments describing the request.</param>
        /// <param name="EditableObject">Object whose parameters will be edited.</param>
        /// <param name="Title">Title of form.</param>
        /// <returns>Data form containing editable parameters.</returns>
        public static async Task <DataForm> GetEditableForm(XmppClient Client, IqEventArgs e, object EditableObject, string Title)
        {
            Type     T = EditableObject.GetType();
            string   DefaultLanguageCode = GetDefaultLanguageCode(T);
            DataForm Parameters          = new DataForm(Client, FormType.Form, e.To, e.From);
            Language Language            = await ConcentratorServer.GetLanguage(e.Query, DefaultLanguageCode);

            Namespace Namespace = await Language.GetNamespaceAsync(T.Namespace);

            List <Field> Fields = new List <Field>();
            List <Page>  Pages  = new List <Page>();
            Dictionary <string, Page>             PageByLabel = new Dictionary <string, Page>();
            Dictionary <string, Section>          SectionByPageAndSectionLabel = null;
            List <KeyValuePair <string, string> > Options = null;
            string                     Header;
            string                     ToolTip;
            string                     PageLabel;
            string                     SectionLabel;
            string                     s;
            int                        StringId;
            bool                       Required;
            bool                       ReadOnly;
            bool                       Masked;
            bool                       Alpha;
            bool                       DateOnly;
            HeaderAttribute            HeaderAttribute;
            ToolTipAttribute           ToolTipAttribute;
            PageAttribute              PageAttribute;
            SectionAttribute           SectionAttribute;
            OptionAttribute            OptionAttribute;
            TextAttribute              TextAttribute;
            RegularExpressionAttribute RegularExpressionAttribute;
            LinkedList <string>        TextAttributes;
            RangeAttribute             RangeAttribute;
            ValidationMethod           ValidationMethod;
            Type                       PropertyType;
            Field                      Field;
            Page                       DefaultPage = null;
            Page                       Page;

            if (Namespace == null)
            {
                Namespace = await Language.CreateNamespaceAsync(T.Namespace);
            }

            foreach (PropertyInfo PI in T.GetRuntimeProperties())
            {
                if (!PI.CanRead || !PI.CanWrite)
                {
                    continue;
                }

                Header           = ToolTip = PageLabel = SectionLabel = null;
                TextAttributes   = null;
                ValidationMethod = null;
                Required         = ReadOnly = Masked = Alpha = DateOnly = false;

                foreach (Attribute Attr in PI.GetCustomAttributes())
                {
                    if ((HeaderAttribute = Attr as HeaderAttribute) != null)
                    {
                        Header   = HeaderAttribute.Header;
                        StringId = HeaderAttribute.StringId;
                        if (StringId > 0)
                        {
                            Header = await Namespace.GetStringAsync(StringId, Header);
                        }
                    }
                    else if ((ToolTipAttribute = Attr as ToolTipAttribute) != null)
                    {
                        ToolTip  = ToolTipAttribute.ToolTip;
                        StringId = ToolTipAttribute.StringId;
                        if (StringId > 0)
                        {
                            ToolTip = await Namespace.GetStringAsync(StringId, ToolTip);
                        }
                    }
                    else if ((PageAttribute = Attr as PageAttribute) != null)
                    {
                        PageLabel = PageAttribute.Label;
                        StringId  = PageAttribute.StringId;
                        if (StringId > 0)
                        {
                            PageLabel = await Namespace.GetStringAsync(StringId, PageLabel);
                        }
                    }
                    else if ((SectionAttribute = Attr as SectionAttribute) != null)
                    {
                        SectionLabel = SectionAttribute.Label;
                        StringId     = SectionAttribute.StringId;
                        if (StringId > 0)
                        {
                            SectionLabel = await Namespace.GetStringAsync(StringId, SectionLabel);
                        }
                    }
                    else if ((TextAttribute = Attr as TextAttribute) != null)
                    {
                        if (TextAttributes == null)
                        {
                            TextAttributes = new LinkedList <string>();
                        }

                        StringId = TextAttribute.StringId;
                        if (StringId > 0)
                        {
                            TextAttributes.AddLast(await Namespace.GetStringAsync(StringId, TextAttribute.Label));
                        }
                        else
                        {
                            TextAttributes.AddLast(TextAttribute.Label);
                        }
                    }
                    else if ((OptionAttribute = Attr as OptionAttribute) != null)
                    {
                        if (Options == null)
                        {
                            Options = new List <KeyValuePair <string, string> >();
                        }

                        StringId = OptionAttribute.StringId;
                        if (StringId > 0)
                        {
                            Options.Add(new KeyValuePair <string, string>(OptionAttribute.Option.ToString(),
                                                                          await Namespace.GetStringAsync(StringId, TextAttribute.Label)));
                        }
                        else
                        {
                            Options.Add(new KeyValuePair <string, string>(OptionAttribute.Option.ToString(), OptionAttribute.Label));
                        }
                    }
                    else if ((RegularExpressionAttribute = Attr as RegularExpressionAttribute) != null)
                    {
                        ValidationMethod = new RegexValidation(RegularExpressionAttribute.Pattern);
                    }
                    else if ((RangeAttribute = Attr as RangeAttribute) != null)
                    {
                        ValidationMethod = new RangeValidation(RangeAttribute.Min, RangeAttribute.Max);
                    }
                    else if (Attr is OpenAttribute)
                    {
                        ValidationMethod = new OpenValidation();
                    }
                    else if (Attr is RequiredAttribute)
                    {
                        Required = true;
                    }
                    else if (Attr is ReadOnlyAttribute)
                    {
                        ReadOnly = true;
                    }
                    else if (Attr is MaskedAttribute)
                    {
                        Masked = true;
                    }
                    else if (Attr is AlphaChannelAttribute)
                    {
                        Alpha = true;
                    }
                    else if (Attr is DateOnlyAttribute)
                    {
                        DateOnly = true;
                    }
                }

                if (Header == null)
                {
                    continue;
                }

                PropertyType = PI.PropertyType;
                Field        = null;

                if (PropertyType == typeof(string[]))
                {
                    if (ValidationMethod == null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    if (Options == null)
                    {
                        Field = new TextMultiField(Parameters, PI.Name, Header, Required, (string[])PI.GetValue(EditableObject),
                                                   null, ToolTip, StringDataType.Instance, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                    else
                    {
                        Field = new ListMultiField(Parameters, PI.Name, Header, Required, (string[])PI.GetValue(EditableObject),
                                                   Options.ToArray(), ToolTip, StringDataType.Instance, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                }
                else if (PropertyType == typeof(Enum))
                {
                    if (ValidationMethod == null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    if (Options == null)
                    {
                        Options = new List <KeyValuePair <string, string> >();

                        foreach (string Option in Enum.GetNames(PropertyType))
                        {
                            Options.Add(new KeyValuePair <string, string>(Option, Option));
                        }
                    }

                    Field = new ListSingleField(Parameters, PI.Name, Header, Required, new string[] { PI.GetValue(EditableObject).ToString() },
                                                Options.ToArray(), ToolTip, null, ValidationMethod, string.Empty, false, ReadOnly, false);
                }
                else if (PropertyType == typeof(bool))
                {
                    if (ValidationMethod == null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    Field = new BooleanField(Parameters, PI.Name, Header, Required,
                                             new string[] { CommonTypes.Encode((bool)PI.GetValue(EditableObject)) },
                                             Options?.ToArray(), ToolTip, BooleanDataType.Instance, ValidationMethod,
                                             string.Empty, false, ReadOnly, false);
                }
                else
                {
                    DataType DataType;

                    if (PropertyType == typeof(string))
                    {
                        DataType = StringDataType.Instance;
                    }
                    else if (PropertyType == typeof(byte))
                    {
                        DataType = ByteDataType.Instance;
                    }
                    else if (PropertyType == typeof(short))
                    {
                        DataType = ShortDataType.Instance;
                    }
                    else if (PropertyType == typeof(int))
                    {
                        DataType = IntDataType.Instance;
                    }
                    else if (PropertyType == typeof(long))
                    {
                        DataType = LongDataType.Instance;
                    }
                    else if (PropertyType == typeof(sbyte))
                    {
                        DataType = ShortDataType.Instance;

                        if (ValidationMethod == null)
                        {
                            ValidationMethod = new RangeValidation(sbyte.MinValue.ToString(), sbyte.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(ushort))
                    {
                        DataType = IntDataType.Instance;

                        if (ValidationMethod == null)
                        {
                            ValidationMethod = new RangeValidation(ushort.MinValue.ToString(), ushort.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(uint))
                    {
                        DataType = LongDataType.Instance;

                        if (ValidationMethod == null)
                        {
                            ValidationMethod = new RangeValidation(uint.MinValue.ToString(), uint.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(ulong))
                    {
                        DataType = IntegerDataType.Instance;

                        if (ValidationMethod == null)
                        {
                            ValidationMethod = new RangeValidation(ulong.MinValue.ToString(), ulong.MaxValue.ToString());
                        }
                    }
                    else if (PropertyType == typeof(DateTime))
                    {
                        if (DateOnly)
                        {
                            DataType = DateDataType.Instance;
                        }
                        else
                        {
                            DataType = DateTimeDataType.Instance;
                        }
                    }
                    else if (PropertyType == typeof(decimal))
                    {
                        DataType = DecimalDataType.Instance;
                    }
                    else if (PropertyType == typeof(double))
                    {
                        DataType = DoubleDataType.Instance;
                    }
                    else if (PropertyType == typeof(float))
                    {
                        DataType = DoubleDataType.Instance;                            // Use xs:double anyway
                    }
                    else if (PropertyType == typeof(TimeSpan))
                    {
                        DataType = TimeDataType.Instance;
                    }
                    else if (PropertyType == typeof(Uri))
                    {
                        DataType = AnyUriDataType.Instance;
                    }
                    else if (PropertyType == typeof(SKColor))
                    {
                        if (Alpha)
                        {
                            DataType = ColorAlphaDataType.Instance;
                        }
                        else
                        {
                            DataType = ColorDataType.Instance;
                        }
                    }
                    else
                    {
                        DataType = null;
                    }

                    if (ValidationMethod == null)
                    {
                        ValidationMethod = new BasicValidation();
                    }

                    if (Masked)
                    {
                        Field = new TextPrivateField(Parameters, PI.Name, Header, Required, new string[] { (string)PI.GetValue(EditableObject) },
                                                     Options?.ToArray(), ToolTip, StringDataType.Instance, ValidationMethod,
                                                     string.Empty, false, ReadOnly, false);
                    }
                    else if (Options == null)
                    {
                        Field = new TextSingleField(Parameters, PI.Name, Header, Required, new string[] { (string)PI.GetValue(EditableObject) },
                                                    null, ToolTip, StringDataType.Instance, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                    else
                    {
                        Field = new ListSingleField(Parameters, PI.Name, Header, Required, new string[] { (string)PI.GetValue(EditableObject) },
                                                    Options.ToArray(), ToolTip, StringDataType.Instance, ValidationMethod, string.Empty, false, ReadOnly, false);
                    }
                }

                if (Field == null)
                {
                    continue;
                }

                Fields.Add(Field);

                if (string.IsNullOrEmpty(PageLabel))
                {
                    if (DefaultPage == null)
                    {
                        DefaultPage = new Page(Parameters, string.Empty);
                        Pages.Add(DefaultPage);
                        PageByLabel[string.Empty] = DefaultPage;
                    }

                    Page      = DefaultPage;
                    PageLabel = string.Empty;
                }
                else
                {
                    if (!PageByLabel.TryGetValue(PageLabel, out Page))
                    {
                        Page = new Page(Parameters, PageLabel);
                        Pages.Add(Page);
                        PageByLabel[PageLabel] = Page;
                    }
                }

                if (string.IsNullOrEmpty(SectionLabel))
                {
                    if (TextAttributes != null)
                    {
                        foreach (string Text in TextAttributes)
                        {
                            Page.Add(new TextElement(Parameters, Text));
                        }
                    }

                    Page.Add(new FieldReference(Parameters, Field.Var));
                }
                else
                {
                    if (SectionByPageAndSectionLabel == null)
                    {
                        SectionByPageAndSectionLabel = new Dictionary <string, Section>();
                    }

                    s = PageLabel + " \xa0 " + SectionLabel;
                    if (!SectionByPageAndSectionLabel.TryGetValue(s, out Section Section))
                    {
                        Section = new Section(Parameters, SectionLabel);
                        SectionByPageAndSectionLabel[s] = Section;

                        Page.Add(Section);
                    }

                    if (TextAttributes != null)
                    {
                        foreach (string Text in TextAttributes)
                        {
                            Section.Add(new TextElement(Parameters, Text));
                        }
                    }

                    Section.Add(new FieldReference(Parameters, Field.Var));
                }
            }

            Parameters.Title  = Title;
            Parameters.Fields = Fields.ToArray();
            Parameters.Pages  = Pages.ToArray();

            return(Parameters);
        }
Exemple #11
0
 internal void AddTextRun(int start, int length, TextAttributes attributes)
 {
     _runs.Add(new AttributedTextRun(start, length, attributes));
 }
        TextAttributeModel IConverter <TextAttributeModel, TextAttributes> .ConvertTo(TextAttributes text)
        {
            if (text == null)
            {
                return(null);
            }

            return(new TextAttributeModel()
            {
                Id = text.Id,
                WatermarkFont = text.WatermarkFont,
                WatermarkFontSize = text.WatermarkFontSize,
                WatermarkText = text.WatermarkText,
                SignatureFont = text.SignatureFont,
                SignatureFontSize = text.SignatureFontSize,
                SignatureText = text.SignatureText,
                StampFont = text.StampFont,
                StampFontSize = text.StampFontSize,
                StampText = text.StampText,
                Alpha = text.Alpha == default(int) ? 80 : text.Alpha
            });
        }
Exemple #13
0
        public static void WatermarkImage(string path, HttpPostedFileBase file,
                                          ImageAttrModel attributes, TextAttributes textAttributes)
        {
            if (textAttributes == null)
            {
                textAttributes = new TextAttributes()
                {
                    WatermarkFont     = "Bell MT",
                    WatermarkFontSize = 60,
                    WatermarkText     = "*****@*****.**",
                    SignatureFont     = "Edwardian Script ITC",
                    SignatureFontSize = 43,
                    SignatureText     = "© Alexander Serebryakov",
                    StampFont         = "Bell MT",
                    StampFontSize     = 45,
                    StampText         = "www.askanio.ru"
                };
            }

            Random random = new Random();

            var watermarkFormat = new StringFormat()
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            var textFormat = new StringFormat()
            {
                Alignment     = StringAlignment.Near,
                LineAlignment = StringAlignment.Near
            };

            using (Image image = Image.FromStream(file.InputStream))
            {
                using (Graphics imageGraphics = Graphics.FromImage(image))
                {
                    imageGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    if (attributes.IsSignatureApplied)
                    {
                        using (Font signatureFont = new Font(textAttributes.SignatureFont, textAttributes.SignatureFontSize, FontStyle.Regular, GraphicsUnit.Pixel))
                        {
                            //Font adaptedWatermarlFont = CalculateFont(imageGraphics, signature, new Size(image.Width / 4, image.Height / 4), signatureFont);
                            SizeF actualSize = imageGraphics.MeasureString(textAttributes.SignatureText, signatureFont);
                            imageGraphics.DrawString(textAttributes.SignatureText, signatureFont,
                                                     attributes.IsSignatureBlack ? Brushes.Black : Brushes.White,
                                                     attributes.IsRightSide ? new PointF(image.Width - actualSize.Width, image.Height - actualSize.Height) : new PointF(10f, image.Height - actualSize.Height),
                                                     textFormat);
                        }
                    }
                    if (attributes.IsWebSiteTitleApplied)
                    {
                        using (Font stampFont = new Font(textAttributes.StampFont, textAttributes.StampFontSize, FontStyle.Regular, GraphicsUnit.Pixel))
                        {
                            // Font adaptedWatermarlFont = CalculateFont(imageGraphics, stamp, new Size(120, 20), stampFont);
                            SizeF actualSize = imageGraphics.MeasureString(textAttributes.StampText, stampFont);
                            imageGraphics.DrawString(textAttributes.StampText, stampFont,
                                                     attributes.IsWebSiteTitleBlack ? Brushes.Black : Brushes.White,
                                                     attributes.IsRightSide ? new PointF(image.Width - actualSize.Width, image.Height - actualSize.Height - 60f) : new PointF(10f, image.Height - actualSize.Height - 60f),
                                                     textFormat);
                        }
                    }
                    if (attributes.IsWatermarkApplied)
                    {
                        using (Font watermarkFont = new Font(textAttributes.WatermarkFont, textAttributes.WatermarkFontSize, FontStyle.Regular, GraphicsUnit.Pixel))
                        {
                            // Font adaptedWatermarkFont = CalculateFont(imageGraphics, watermark, new Size(image.Width / 2, image.Height / 2), watermarkFont);
                            SizeF actualSize = imageGraphics.MeasureString(textAttributes.WatermarkText, watermarkFont);
                            imageGraphics.DrawString(textAttributes.WatermarkText, watermarkFont,
                                                     new SolidBrush(Color.FromArgb(80, attributes.IsWatermarkBlack? Color.Black : Color.White)),
                                                     (image.Width / 2) + random.Next(40), (image.Height / 2) + random.Next(40),
                                                     watermarkFormat);
                        }
                    }

                    if (Array.IndexOf(image.PropertyIdList, 274) > -1)
                    {
                        var orientation = (int)image.GetPropertyItem(274).Value[0];
                        switch (orientation)
                        {
                        case 1:
                            // No rotation required.
                            break;

                        case 2:
                            image.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            break;

                        case 3:
                            image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            break;

                        case 4:
                            image.RotateFlip(RotateFlipType.Rotate180FlipX);
                            break;

                        case 5:
                            image.RotateFlip(RotateFlipType.Rotate90FlipX);
                            break;

                        case 6:
                            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            break;

                        case 7:
                            image.RotateFlip(RotateFlipType.Rotate270FlipX);
                            break;

                        case 8:
                            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            image.RotateFlip(RotateFlipType.Rotate90FlipNone);;
                            break;
                        }
                        // This EXIF data is now invalid and should be removed.
                        image.RemovePropertyItem(274);
                    }

                    image.Save(HttpContext.Current.Server.MapPath(path), image.RawFormat);
                }
            }
        }
Exemple #14
0
 static AutomationIdentifierConstants()
 {
     if (OSVersionHelper.IsOsWindows10RS2OrGreater)
     {
         LastSupportedProperty      = Properties.Size;
         LastSupportedEvent         = Events.Changes;
         LastSupportedPattern       = Patterns.CustomNavigation;
         LastSupportedTextAttribute = TextAttributes.SayAsInterpretAs;
         LastSupportedControlType   = ControlTypes.AppBar;
     }
     else if (OSVersionHelper.IsOsWindows10RS1OrGreater)
     {
         LastSupportedProperty      = Properties.FullDescription;
         LastSupportedEvent         = Events.Changes;
         LastSupportedPattern       = Patterns.CustomNavigation;
         LastSupportedTextAttribute = TextAttributes.CaretBidiMode;
         LastSupportedControlType   = ControlTypes.AppBar;
     }
     else if (OSVersionHelper.IsOsWindows10TH2OrGreater)
     {
         LastSupportedProperty      = Properties.LocalizedLandmarkType;
         LastSupportedEvent         = Events.TextEdit_ConversionTargetChanged;
         LastSupportedPattern       = Patterns.CustomNavigation;
         LastSupportedTextAttribute = TextAttributes.CaretBidiMode;
         LastSupportedControlType   = ControlTypes.AppBar;
     }
     else if (OSVersionHelper.IsOsWindows10OrGreater)
     {
         LastSupportedProperty      = Properties.AnnotationObjects;
         LastSupportedEvent         = Events.TextEdit_ConversionTargetChanged;
         LastSupportedPattern       = Patterns.CustomNavigation;
         LastSupportedTextAttribute = TextAttributes.CaretBidiMode;
         LastSupportedControlType   = ControlTypes.AppBar;
     }
     else if (OSVersionHelper.IsOsWindows8Point1OrGreater)
     {
         LastSupportedProperty      = Properties.IsPeripheral;
         LastSupportedEvent         = Events.TextEdit_ConversionTargetChanged;
         LastSupportedPattern       = Patterns.TextEdit;
         LastSupportedTextAttribute = TextAttributes.CaretBidiMode;
         LastSupportedControlType   = ControlTypes.AppBar;
     }
     else if (OSVersionHelper.IsOsWindows8OrGreater)
     {
         LastSupportedProperty      = Properties.FlowsFrom;
         LastSupportedEvent         = Events.DropTarget_Dropped;
         LastSupportedPattern       = Patterns.DropTarget;
         LastSupportedTextAttribute = TextAttributes.CaretBidiMode;
         LastSupportedControlType   = ControlTypes.SemanticZoom;
     }
     else if (OSVersionHelper.IsOsWindows7OrGreater ||
              (OSVersionHelper.IsOsWindowsVistaOrGreater && UiaCoreTypesApi.SupportsWin7Identifiers()))
     {
         LastSupportedProperty      = Properties.IsSynchronizedInputPatternAvailable;
         LastSupportedEvent         = Events.InputDiscarded;
         LastSupportedPattern       = Patterns.SynchronizedInput;
         LastSupportedTextAttribute = TextAttributes.UnderlineStyle;
         LastSupportedControlType   = ControlTypes.Separator;
     }
     else
     {
         LastSupportedProperty      = Properties.TransformCanRotate;
         LastSupportedEvent         = Events.Window_WindowClosed;
         LastSupportedPattern       = Patterns.ScrollItem;
         LastSupportedTextAttribute = TextAttributes.UnderlineStyle;
         LastSupportedControlType   = ControlTypes.Separator;
     }
 }
 /// <summary>
 /// Sets the nucelotide attributes from the selected options
 /// </summary>
 /// <param name="bioSymbol"></param>
 /// <param name="ta"></param>
 public void GetAttributes(IBioSymbol bioSymbol, ref TextAttributes ta)
 {
     ta.Foreground = GetNucleotideColor(bioSymbol);
 }
Exemple #16
0
 public SimpleTextRunProperties(FontFamily fontName, double fontSize, TextAttributes textAttributes)
 {
     _fontFamily     = fontName;
     _fontSize       = fontSize;
     _textAttributes = textAttributes;
 }
Exemple #17
0
        private static bool HandleAttributes(
            IList <IAttributedTextRun> runs,
            TextWriter writer,
            NSAttributedString target,
            NSDictionary attrs,
            NSRange range)
        {
            var text = target.Substring(range.Location, range.Length).Value;

            var formatAttributes = new TextAttributes();
            var run = new AttributedTextRun((int)range.Location, (int)range.Length, formatAttributes);

            NSObject font;

            if (attrs.TryGetValue(NSStringAttributeKey.Font, out font))
            {
                var actualFont = (NSFont)font;
#if __MACOS__
                var fontName = actualFont.FontName;
#else
                var fontName = actualFont.Name;
#endif

                formatAttributes.SetFontSize((float)actualFont.PointSize);
                if (!fontName.StartsWith(".", System.StringComparison.Ordinal))
                {
                    formatAttributes.SetFontName(fontName);
                }
                else
                {
                    if (fontName.Contains("Italic"))
                    {
                        formatAttributes.SetItalic(true);
                    }

                    if (fontName.Contains("Bold"))
                    {
                        formatAttributes.SetBold(true);
                    }
                }
            }

            NSObject underline;
            if (attrs.TryGetValue(NSStringAttributeKey.UnderlineStyle, out underline))
            {
                var number = underline as NSNumber;
                if (number != null && number.Int32Value > 0)
                {
                    formatAttributes.SetUnderline(true);
                }
            }

            NSObject strikethrough;
            if (attrs.TryGetValue(NSStringAttributeKey.StrikethroughStyle, out strikethrough))
            {
                var number = strikethrough as NSNumber;
                if (number != null && number.Int32Value > 0)
                {
                    formatAttributes.SetStrikethrough(true);
                }
            }

#if MONOMAC
            NSObject superscript;
            if (attrs.TryGetValue(NSStringAttributeKey.Superscript, out superscript))
            {
                var number = superscript as NSNumber;
                if (number != null && number.Int32Value == -1)
                {
                    formatAttributes.SetSubscript(true);
                }
                else if (number != null && number.Int32Value == 1)
                {
                    formatAttributes.SetSuperscript(true);
                }
            }
#endif

            NSObject color;
            if (attrs.TryGetValue(NSStringAttributeKey.ForegroundColor, out color))
            {
                var colorObject = color as NSColor;
                if (colorObject != null)
                {
                    formatAttributes.SetForegroundColor(colorObject.ToHex());
                }
            }

            NSObject backgroundColor;
            if (attrs.TryGetValue(NSStringAttributeKey.BackgroundColor, out backgroundColor))
            {
                var colorObject = backgroundColor as NSColor;
                if (colorObject != null)
                {
                    formatAttributes.SetBackgroundColor(colorObject.ToHex());
                }
            }

#if MONOMAC
            NSObject paragraphStyleAsObject;
            if (attrs.TryGetValue(NSStringAttributeKey.ParagraphStyle, out paragraphStyleAsObject))
            {
                var paragraphStyle = (NSParagraphStyle)paragraphStyleAsObject;
                if (paragraphStyle.TextLists != null && paragraphStyle.TextLists.Length > 0)
                {
                    for (int i = 0; i < paragraphStyle.TextLists.Length; i++)
                    {
                        var textList     = paragraphStyle.TextLists [i];
                        var markerFormat = textList.MarkerFormat;

                        if ("{hyphen}".Equals(textList.MarkerFormat))
                        {
                            formatAttributes.SetUnorderedList(true);
                            formatAttributes.SetMarker(MarkerType.Hyphen);
                        }
                        else
                        {
                            formatAttributes.SetUnorderedList(true);
                            formatAttributes.SetMarker(MarkerType.ClosedCircle);
                        }
                    }
                }
            }
#endif

            if (run.Attributes.Count > 0)
            {
                runs.Add(run);
            }

            writer.Write(text);
            return(false);
        }
Exemple #18
0
 public ImageProcessor(string path, string thumbPath, TextAttributes attributes) : this(path, thumbPath)
 {
     TextAttributes = attributes;
 }
Exemple #19
0
        void UpdateSelection()
        {
            InternalUpdateSelection();

            // update font state
            Boolean HasFont = false;
            FontFamily Family = new FontFamily("Arial");
            FontStyle Style = FontStyles.Normal;
            FontWeight Weight = FontWeights.Normal;
            Double Size = 14;
            Color Foreground = Colors.Black;
            Color Background = Colors.Transparent;
            TextAlign Alignment = TextAlign.Block;
            TextAttributes Attributes = TextAttributes.None;
            FontStretch Stretch = FontStretches.Normal;

            // determine letter before selection...
            for (int i = SelectionStart - 1; i >= 0; i--)
            {
                Letter Item = LineItems[i] as Letter;

                if (Item == null)
                    continue;

                Family = Item.Label.FontFamily;
                Style = Item.Label.FontStyle;
                Weight = Item.Label.FontWeight;
                Size = Item.FontSize;
                Foreground = Item.Foreground;
                Background = Item.Background;
                Attributes = Item.TextAttributes;
                Alignment = Item.Alignment;
                Stretch = Item.Label.FontStretch;

                break;
            }

            m_FontFamily = Family;
            m_FontStyle = Style;
            m_FontWeight = Weight;
            m_FontSize = Size;
            m_FontStretch = Stretch;
            m_FontForeground = Foreground;
            m_FontBackground = Background;
            m_TextAlignment = Alignment;
            m_TextAttributes = Attributes;

            for (int i = SelectionStart; i < SelectionStart + SelectionLength; i++)
            {
                Letter Item = LineItems[i] as Letter;

                if (Item == null)
                    continue;

                if (!HasFont)
                {
                    Family = Item.Label.FontFamily;
                    Style = Item.Label.FontStyle;
                    Weight = Item.Label.FontWeight;
                    Size = Item.FontSize;
                    Foreground = Item.Foreground;
                    Background = Item.Background;
                    Attributes = Item.TextAttributes;
                    Alignment = Item.Alignment;
                    Stretch = Item.Label.FontStretch;

                    HasFont = true;
                }
                else
                {
                    if (!Family.Equals(Item.Label.FontFamily) ||
                        !Style.Equals(Item.Label.FontStyle) ||
                        !Weight.Equals(Item.Label.FontWeight) ||
                        (Size != Item.FontSize) ||
                        !Foreground.Equals(Item.Foreground) ||
                        !Background.Equals(Item.Background) ||
                        (Alignment != Item.Alignment) ||
                        (Attributes != Item.TextAttributes) ||
                        (Stretch != Item.Label.FontStretch)
                        )
                    {
                        // only homogenous formatting may be saved...
                        return;
                    }
                }
            }

            m_FontFamily = Family;
            m_FontStyle = Style;
            m_FontWeight = Weight;
            m_FontSize = Size;
            m_FontForeground = Foreground;
            m_FontBackground = Background;
            m_TextAlignment = Alignment;
            m_TextAttributes = Attributes;
            m_FontStretch = Stretch;
        }