Esempio n. 1
0
        public override ICollection <String> Flatten(StateNode state)
        {
            String res = (String)this.MemberwiseClone();

            res.ApplyState(state);
            return(new[] { res });
        }
Esempio n. 2
0
        public SpannableString ConvertToSpannable(StateNode state, DisplayMetrics displayMetrics)
        {
            var nodes = Flatten(state).TrimNewLines();

            var s = new SpannableString(string.Concat(nodes as IEnumerable<TextEx>));
            int start = 0;
            foreach (var n in nodes)
            {
                if (string.IsNullOrEmpty(n.Text))
                {
                    if (n is StringAnchor a)
                    {
                        //s.SetSpan(new ClickableSpan(a.Owner), start, start + a.Length, SpanTypes.InclusiveExclusive);
                        //s.SetSpan(new UnderlineSpan(), start, start + a.Length, SpanTypes.InclusiveExclusive);
                    }
                    continue;
                }

                if (n.Bold != null || n.Italic != null || n.FontSize != null || n.Foreground != null)
                {
                    TypefaceStyle style = 0;
                    if (n.Bold == true && n.Italic == true)
                        style = TypefaceStyle.BoldItalic;
                    else if (n.Bold == true)
                        style = TypefaceStyle.Bold;
                    else if (n.Italic == true)
                        style = TypefaceStyle.Italic;
                    else
                        style = TypefaceStyle.Normal;


                    ColorStateList color = null;
                    if (n.Foreground != null) color = ColorStateList.ValueOf(new AColor(
                            (byte)(n.Foreground.Value.R * 255),
                            (byte)(n.Foreground.Value.G * 255),
                            (byte)(n.Foreground.Value.B * 255),
                            (byte)(n.Foreground.Value.A * 255)
                        ));

                    int fontSize = -1;

                    if (n.FontSize != null)
                        fontSize = (int) Math.Round(TypedValue.ApplyDimension(ComplexUnitType.Sp, (float) n.FontSize.Value, displayMetrics), MidpointRounding.AwayFromZero);

                    s.SetSpan(new TextAppearanceSpan(null, style, fontSize, color, null), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                }
                if (n.Sub == true)
                    s.SetSpan(new SubscriptSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                if (n.Super == true)
                    s.SetSpan(new SuperscriptSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                if (n.Strike == true)
                    s.SetSpan(new StrikethroughSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);
                if (n.Underline == true)
                    s.SetSpan(new UnderlineSpan(), start, start + n.Text.Length, SpanTypes.InclusiveExclusive);

                start += n.Text.Length;
            }

            return s;
        }
Esempio n. 3
0
 public override ICollection<String> Flatten(StateNode state)
 {
     var res = base.Flatten(state) as List<String>;
     if (Nodes.Count > 0 && Nodes[Nodes.Count - 1].GetType() != typeof(Block))
     {
         var linebreaks = new String { Text = "\n\n" };
         linebreaks.ApplyState(this);
         linebreaks.ApplyState(state);
         res.Add(linebreaks);
     }
     return res;
 }
Esempio n. 4
0
        public override ICollection<String> Flatten(StateNode state)
        {
            var newstate = new StateNode();
            newstate.ApplyState(this);
            newstate.ApplyState(state);

            List<String> res = new List<String>(Nodes.Count + 2);
            var anchor = new StringAnchor { Owner = this };
            res.Add(anchor);
            bool donefirst = false;

            foreach (var node in Nodes)
            {
                if (Pad && donefirst) res.Add(new String(" "));
                res.AddRange(node.Flatten(newstate));
                donefirst = true;
            }
            
            return res;
        }
Esempio n. 5
0
        public Span FlattenToSpan(StateNode state = null)
        {
            var flat = Flatten(state ?? new StateNode());

            return(new Span(flat.TrimNewLines()));
        }
Esempio n. 6
0
 public abstract ICollection <String> Flatten(StateNode state);
Esempio n. 7
0
 public override ICollection <String> Flatten(StateNode state)
 {
     return(new String[] { });
 }