コード例 #1
0
        internal static FormattedText ToFormattedText(XElement e)
        {
            // The text representation of e.
            String text = ToText(e);

            if (text == String.Empty)
            {
                return(null);
            }

            // e is a w:t element, it must exist inside a w:r element or a w:tabs, lets climb until we find it.
            while (!e.Name.Equals(XName.Get("r", DocX.w.NamespaceName)) && !e.Name.Equals(XName.Get("tabs", DocX.w.NamespaceName)))
            {
                e = e.Parent;
            }

            // e is a w:r element, lets find the rPr element.
            XElement rPr = e.Element(XName.Get("rPr", DocX.w.NamespaceName));

            FormattedText ft = new FormattedText();

            ft.text       = text;
            ft.index      = 0;
            ft.formatting = null;

            // Return text with formatting.
            if (rPr != null)
            {
                ft.formatting = Formatting.Parse(rPr);
            }

            return(ft);
        }
コード例 #2
0
        internal static FormattedText ToFormattedText(XElement e)
        {
            // The text representation of e.
            String text = ToText(e);

            if (text == String.Empty)
            {
                return(null);
            }

            // Do not read text from Fallback.
            var fallbackValue = e.AncestorsAndSelf().FirstOrDefault(x => x.Name.Equals(XName.Get("Fallback", DocX.mc.NamespaceName)));

            if (fallbackValue != null)
            {
                return(null);
            }

            // e is a w:t element, it must exist inside a w:r element or a w:tabs, lets climb until we find it.
            while ((e != null) && !e.Name.Equals(XName.Get("r", DocX.w.NamespaceName)) && !e.Name.Equals(XName.Get("tabs", DocX.w.NamespaceName)))
            {
                e = e.Parent;
            }

            FormattedText ft = new FormattedText();

            ft.text       = text;
            ft.index      = 0;
            ft.formatting = null;

            if (e != null)
            {
                // e is a w:r element, lets find the rPr element.
                XElement rPr = e.Element(XName.Get("rPr", DocX.w.NamespaceName));

                // Return text with formatting.
                if (rPr != null)
                {
                    ft.formatting = Formatting.Parse(rPr);
                }
            }

            return(ft);
        }