コード例 #1
0
        // when applying styles, we want to preserve any special treatments to paragraphs
        // because that would be tedious for the user to restore manually if their intention
        // was to keep those colors, but we want to clear all color styling from every other
        // element type like headings, et al.
        private void ClearInlineStyles(string index, bool paragraph)
        {
            var elements = page.Root.Descendants()
                           .Where(e => e.Attribute("quickStyleIndex")?.Value == index);

            if (elements != null)
            {
                foreach (var element in elements)
                {
                    stylizer.Clear(element, paragraph ? Stylizer.Clearing.Gray : Stylizer.Clearing.All);
                }
            }
        }
コード例 #2
0
        private bool StylizeParagraphs()
        {
            // find all paragraphs - OE elements - that have selections
            // TODO: filter out MetaNames.TaggingBank?
            var elements = page.Root.Descendants(ns + "T")
                           .Where(e => e.Attributes("selected").Any(a => a.Value.Equals("all")))
                           .Select(p => p.Parent);

            if (elements?.Any() != true)
            {
                return(false);
            }

            var css = style.ToCss();

            var applied = new Style(style)
            {
                ApplyColors = true
            };

            foreach (var element in elements)
            {
                // clear any existing style on or within the paragraph
                stylizer.Clear(element, style.ApplyColors ? Stylizer.Clearing.All : Stylizer.Clearing.None);

                SetQuickStyle(page, element, style);

                // style may still exist if apply colors if false and there are colors
                var attr = element.Attribute("style");
                if (attr == null)
                {
                    // blast style onto paragraph, let OneNote normalize across
                    // children if it wants
                    attr = new XAttribute("style", css);
                    element.Add(attr);
                }
                else
                {
                    applied.MergeColors(new Style(attr.Value));
                    attr.Value = applied.ToCss();
                }

                ApplySpacing(element, "spaceBefore", style.SpaceBefore);
                ApplySpacing(element, "spaceAfter", style.SpaceAfter);
                ApplySpacing(element, "spaceBetween", style.Spacing);

                ApplyToList(element, style);
            }

            return(true);
        }