Exemple #1
0
        // To allow us to keep track of the sections and revert formatting
        // as we go in and out of sections of the document.
        private void HandleGroup(Common.Text.RTF.Parser.RTF rtf)
        {
            //start group - save the current formatting on to a stack
            //end group - go back to the formatting at the current group
            if (_sectionStack == null)
            {
                _sectionStack = new Stack();
            }

            if (rtf.Major == Major.BeginGroup)
            {
                _sectionStack.Push(_style.Clone());
                //spec specifies resetting unicode ignore at begin group as an attempt at error
                //recovery.
                _skipCount = 0;
            }
            else if (rtf.Major == Major.EndGroup)
            {
                if (_sectionStack.Count > 0)
                {
                    FlushText(rtf, false);

                    _style = (RtfSectionStyle)_sectionStack.Pop();
                }
            }
        }
Exemple #2
0
 public RtfImporter(Stream stream, IDocument document)
 {
     this.stream    = stream;
     this.rtfParser = new Common.Text.RTF.Parser.RTF(stream);
     this.document  = document;
     _style         = new RtfSectionStyle();
 }
Exemple #3
0
        public object Clone()
        {
            var newStyle = new RtfSectionStyle();

            newStyle.Color             = Color;
            newStyle.ParLineLeftIndent = ParLineLeftIndent;
            newStyle.Align             = Align;
            newStyle.FontName          = FontName;
            newStyle.FontSize          = FontSize;
            newStyle.SectionAttribute  = SectionAttribute;
            newStyle.Visible           = Visible;
            newStyle.SkipWidth         = SkipWidth;

            return(newStyle);
        }
Exemple #4
0
        public virtual void Add(string text, RtfSectionStyle style, int startX, bool newLine)
        {
            if (text == null)
            {
                return;
            }

            var attrs = new List <string> ();

            if (style.SectionAttribute.HasFlag(SectionAttribute.Bold))
            {
                attrs.Add("**");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Italic))
            {
                attrs.Add("_");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Strikeout))
            {
                attrs.Add("~~");
            }
            //if (style.SectionAttribute.HasFlag (SectionAttribute.Underline))
            //    attrs.Add ("u");
            //if (style.SectionAttribute.HasFlag (SectionAttribute.Superscript))
            //    attrs.Add ("sup");
            //if (style.SectionAttribute.HasFlag (SectionAttribute.Subscript))
            //    attrs.Add ("sub");

            foreach (var attr in attrs)
            {
                BodyText.Append(string.Format("{0}", attr));
            }

            BodyText.Append(text);

            foreach (var attr in attrs)
            {
                BodyText.Append(string.Format("{0}", attr));
            }

            BodyText.AppendLine();

            if (newLine)
            {
                BodyText.AppendLine();
            }
        }
Exemple #5
0
        public virtual void Add(string text, RtfSectionStyle style, int curX, bool newLine)
        {
            var tagStyle = "";
            var tag      = "span"; //newLine ? "div" : "span";

            if (newLine && inDiv > 0)
            {
                inDiv--;
                // write end div
                // BodyText.Append (string.Format ("</{0}>", tag));
            }

            if (text == null)
            {
                return;
            }

            if (newLine)
            {
                inDiv++;
            }

            var styles = new List <string> ();

            if (style.Color != Xwt.SystemColors.WindowText)
            {
                styles.Add($"color:{style.Color.ToHexString (false)}");
            }
            var trimmed = text.TrimStart();
            var padding = text.Length - trimmed.Length;

            if (padding > 0)
            {
                styles.Add($"padding-left:{padding}em");
            }
            if (styles.Count > 0)
            {
                tagStyle = $"style=\"{string.Join(";",styles)}\"";
            }
            var attrs = new List <string> ();

            if (style.SectionAttribute.HasFlag(SectionAttribute.Bold))
            {
                attrs.Add("b");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Italic))
            {
                attrs.Add("i");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Underline))
            {
                attrs.Add("u");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Strikeout))
            {
                attrs.Add("strike");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Superscript))
            {
                attrs.Add("sup");
            }
            if (style.SectionAttribute.HasFlag(SectionAttribute.Subscript))
            {
                attrs.Add("sub");
            }

            BodyText.Append(string.Format("<{0} {1}>", tag, tagStyle));

            foreach (var attr in attrs)
            {
                BodyText.Append(string.Format("<{0}>", attr));
            }

            BodyText.Append(System.Net.WebUtility.HtmlEncode(trimmed));

            foreach (var attr in attrs)
            {
                BodyText.Append(string.Format("</{0}>", attr));
            }

            //if (!newLine)
            BodyText.Append(string.Format("</{0}>", tag));
            lineLen += text.Length;
            if (newLine)
            {
                lineLen = 0;
                BodyText.Append("<br>");
                BodyText.AppendLine();
            }
        }