예제 #1
0
        public TextSpanDescriptor Span(string?text)
        {
            var style      = DefaultStyle.Clone();
            var descriptor = new TextSpanDescriptor(style);

            if (text == null)
            {
                return(descriptor);
            }

            var items = text
                        .Replace("\r", string.Empty)
                        .Split(new[] { '\n' }, StringSplitOptions.None)
                        .Select(x => new TextBlockSpan
            {
                Text  = x,
                Style = style
            })
                        .ToList();

            AddItemToLastTextBlock(items.First());

            items
            .Skip(1)
            .Select(x => new TextBlock
            {
                Items = new List <ITextBlockItem> {
                    x
                }
            })
            .ToList()
            .ForEach(TextBlocks.Add);

            return(descriptor);
        }
예제 #2
0
        public TextSpanDescriptor Hyperlink(string?text, string url)
        {
            if (IsNullOrEmpty(url))
            {
                throw new ArgumentException("Url cannot be null or empty", nameof(url));
            }

            var style      = DefaultStyle.Clone();
            var descriptor = new TextSpanDescriptor(style);

            if (IsNullOrEmpty(text))
            {
                return(descriptor);
            }

            AddItemToLastTextBlock(new TextBlockHyperlink
            {
                Style = style,
                Text  = text,
                Url   = url
            });

            return(descriptor);
        }
예제 #3
0
        public TextSpanDescriptor SectionLink(string?text, string sectionName)
        {
            if (IsNullOrEmpty(sectionName))
            {
                throw new ArgumentException("Section name cannot be null or empty", nameof(sectionName));
            }

            var style      = DefaultStyle.Clone();
            var descriptor = new TextSpanDescriptor(style);

            if (IsNullOrEmpty(text))
            {
                return(descriptor);
            }

            AddItemToLastTextBlock(new TextBlockSectionlLink
            {
                Style       = style,
                Text        = text,
                SectionName = sectionName
            });

            return(descriptor);
        }