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
        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 #3
0
        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);
            }
        }
Exemple #4
0
        protected override void Write(AttributedTextRenderer renderer, ParagraphBlock obj)
        {
            /*if (!renderer.ImplicitParagraph)
             * {
             * if (!renderer.IsFirstInContainer)
             * {
             *    renderer.EnsureLine();
             * }
             * renderer.Write("<p").WriteAttributes(obj).Write(">");
             * }*/
            renderer.WriteLeafInline(obj);
            renderer.WriteLine();

            /*if (!renderer.ImplicitParagraph)
             * {
             * renderer.WriteLine("</p>");
             * }*/
        }
        protected override void Write(AttributedTextRenderer renderer, HtmlBlock leafBlock)
        {
            bool writeEndOfLines = true;

            if (leafBlock.Lines.Lines != null)
            {
                var lines  = leafBlock.Lines;
                var slices = lines.Lines;
                for (int i = 0; i < lines.Count; i++)
                {
                    if (!writeEndOfLines && i > 0)
                    {
                        renderer.WriteLine();
                    }

                    renderer.Write(ref slices[i].Slice);

                    if (writeEndOfLines)
                    {
                        renderer.WriteLine();
                    }
                }
            }
        }
 protected override void Write(AttributedTextRenderer renderer, LineBreakInline obj)
 {
     renderer.WriteLine();
 }
 protected override void Write(AttributedTextRenderer renderer, LiteralInline obj)
 {
     renderer.Write(ref obj.Content);
 }