示例#1
0
        private void MarkupTextChanged()
        {
            _TextMarkup = null;

            if (_EnableMarkup == true)
            {
                if (MarkupParser.IsMarkup(_Text) == true)
                {
                    _TextMarkup = MarkupParser.Parse(_Text);

                    if (_TextMarkup != null)
                        _TextMarkup.HyperLinkClick += TextMarkupLinkClick;
                }
            }
        }
示例#2
0
        private void MarkupHeaderTextChanged()
        {
            _HeaderTextMarkup = null;

            if (EnableHeaderMarkup == true)
            {
                if (MarkupParser.IsMarkup(_HeaderText) == true)
                {
                    _HeaderTextMarkup = MarkupParser.Parse(_HeaderText);

                    if (_HeaderTextMarkup != null)
                        _HeaderTextMarkup.HyperLinkClick += HeaderTextMarkupLinkClick;
                }
            }
        }
示例#3
0
        private void RenderTextMarkup(Graphics g,
            BodyElement textMarkup, CellVisualStyle style, Rectangle r)
        {
            MarkupDrawContext d =
                new MarkupDrawContext(g, style.Font, style.TextColor, false);

            textMarkup.Arrange(new Rectangle(r.Location, r.Size), d);

            Size size = textMarkup.Bounds.Size;

            switch (style.Alignment)
            {
                case Alignment.MiddleLeft:
                case Alignment.MiddleCenter:
                case Alignment.MiddleRight:
                    if (r.Height > size.Height)
                        r.Y += (r.Height - size.Height) / 2;
                    break;

                default:
                    if (r.Height > size.Height)
                        r.Y = r.Bottom - size.Height;
                    break;
            }

            textMarkup.Bounds = new Rectangle(r.Location, size);

            Region oldClip = g.Clip;

            try
            {
                g.SetClip(r, CombineMode.Intersect);

                textMarkup.Render(d);
            }
            finally
            {
                g.Clip = oldClip;
            }
        }
示例#4
0
        private Size GetMarkupTextSize(Graphics g, 
            BodyElement textMarkup, CellVisualStyle style, int width)
        {
            MarkupDrawContext d =
                new MarkupDrawContext(g, style.Font, style.TextColor, false);

            textMarkup.InvalidateElementsSize();
            textMarkup.Measure(new Size(width, 0), d);

            return (textMarkup.Bounds.Size);
        }
示例#5
0
        private void MarkupGroupTextChanged()
        {
            _GroupTextMarkup = null;

            if (Column != null && Column.EnableGroupHeaderMarkup == true)
            {
                if (MarkupParser.IsMarkup(_Text) == true)
                    _GroupTextMarkup = MarkupParser.Parse(_Text);
            }
        }
示例#6
0
        public static BodyElement Parse(string text)
        {
            StringBuilder plainText = new StringBuilder(text.Length);
            BodyElement root = new BodyElement();
            root.HasExpandElement = false;
            MarkupElement currentParent = root;
            Stack openTags = new Stack();
            openTags.Push(root);
            // Input text is not wrapped into the container tag so we wrap it here
            text = text.Replace(" ", "{ent_nbsp}");
            text = text.Replace("&zwsp;", "{ent_zwsp}");
            text = text.Replace("<", "{ent_lt}");
            text = text.Replace(">", "{ent_gt}");
            text = text.Replace("&", "{ent_amp}");
            text = text.Replace("|", "{ent_l}");
            text = text.Replace("&", "|");
            text = text.Replace("{ent_nbsp}", " ");
            text = text.Replace("{ent_zwsp}", "&zwsp;"); 
            text = text.Replace("{ent_lt}", "<");
            text = text.Replace("{ent_gt}", ">");
            StringReader sr = new StringReader("<"+BodyTag+">" + text + "</"+BodyTag+">");
#if !DEBUG
            try
#endif
            {
                XmlTextReader reader = new XmlTextReader(sr);
                //reader.EntityHandling = EntityHandling.ExpandCharEntities;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == BodyTag)
                            continue;
                        MarkupElement el = CreateMarkupElement(reader.Name);
                        if (el == null)
                        {
                            reader.Skip();
                            continue;
                        }
                        else if (el is ExpandElement)
                            root.HasExpandElement = true;

                        if (el is IActiveMarkupElement)
                            root.ActiveElements.Add(el);

                        // Parse any attributes here
                        if (reader.AttributeCount > 0)
                        {
                            el.ReadAttributes(reader);
                            reader.MoveToElement();
                        }

                        currentParent.Elements.Add(el);

                        if (el is ContainerElement)
                            currentParent = el;

                        if (!reader.IsEmptyElement)
                            openTags.Push(el);
                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        if (reader.Value.Length == 1)
                        {
                            TextElement el = CreateMarkupElement(TextElementName) as TextElement;
                            if (reader.Value == " ")
                            {
                                el.TrailingSpace = true;
                                plainText.Append(' ');
                            }
                            else
                            {
                                el.Text = reader.Value;
                                el.Text = el.Text.Replace("|", "&");
                                el.Text = el.Text.Replace("{ent_l}", "|");
                                el.Text = el.Text.Replace("{ent_amp}", "&&");
                                plainText.Append(el.Text+" ");
                            }
                            currentParent.Elements.Add(el);
                        }
                        else
                        {
                            string s = reader.Value;
                            if (s.StartsWith("\r\n"))
                                s = s.TrimStart(new char[] { '\r', '\n' });
                            s = s.Replace("\r\n", " ");
                            string[] words = s.Split(' ');
                            bool space = false;
                            if (currentParent.Elements.Count > 0 && currentParent.Elements[currentParent.Elements.Count - 1] is NewLine)
                                space = true;
                            for (int i = 0; i < words.Length; i++)
                            {
                                if (words[i].Length == 0)
                                {
                                    if (space)
                                        continue;
                                    space = true;
                                }
                                else
                                    space = false;

                                TextElement el = CreateMarkupElement(TextElementName) as TextElement;
                                el.Text = words[i].Replace("|","&");
                                el.Text = el.Text.Replace("{ent_l}", "|");
                                el.Text = el.Text.Replace("{ent_amp}", "&&");
                                plainText.Append(el.Text + " ");
                                if (i < words.Length - 1)
                                {
                                    el.TrailingSpace = true;
                                    space = true;
                                }

                                currentParent.Elements.Add(el);
                            }
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.Whitespace)
                    {
                        if (reader.Value.IndexOf(' ') >= 0)
                        {
                            TextElement el = CreateMarkupElement(TextElementName) as TextElement;
                            el.TrailingSpace = true;
                            currentParent.Elements.Add(el);
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EntityReference)
                    {
                        TextElement el = CreateMarkupElement(TextElementName) as TextElement;
                        if (reader.Name == "nbsp")
                        {
                            el.TrailingSpace = true;
                        }
                        else if (reader.Name == "zwsp")
                        {
                            el.TrailingSpace = false;
                        }
                        else
                            el.Text = reader.Name;
                        el.EnablePrefixHandling = false;
                        currentParent.Elements.Add(el);
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        MarkupElement el = openTags.Pop() as MarkupElement;
                        if (el != currentParent)
                        {
                            currentParent.Elements.Add(new EndMarkupElement(el));
                        }
                        else
                        {
                            if (currentParent != root)
                                currentParent = currentParent.Parent;
                        }
                    }
                }
            }
#if !DEBUG
            catch
            {
                return null;
            }
#endif
            root.PlainText = plainText.ToString();
            return root;
        }