Пример #1
0
        public static void ReadStyles(XDocument mapStyles, IDictionary <string, XMindStyle> stylesById)
        {
            var nodeStyles = mapStyles.Root.Element(Namespaces.Styles("styles"));

            if (nodeStyles == null)
            {
                return;
            }

            foreach (var style in nodeStyles.Elements(Namespaces.Styles("style")))
            {
                var id = style.AttributeValue("id");

                if (string.IsNullOrWhiteSpace(id))
                {
                    continue;
                }

                if (!style.IsAttributeEquals("type", "topic"))
                {
                    continue;
                }

                var properties = style.Element(Namespaces.Styles("topic-properties"));

                if (properties == null)
                {
                    continue;
                }

                var fillString = properties.AttributeValue(Namespaces.SVG("fill"));

                if (string.IsNullOrWhiteSpace(fillString) || !ColorRegex.IsMatch(fillString))
                {
                    continue;
                }

                int color;

                if (int.TryParse(fillString.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out color))
                {
                    stylesById[id] = new XMindStyle {
                        Color = color
                    };
                }
            }
        }
Пример #2
0
        public static void WriteContent(Document document, XDocument xMapStyles, IRenderer renderer)
        {
            var styles = new XElement(Namespaces.Styles("styles"));

            foreach (var node in document.Nodes)
            {
                var color = renderer.FindColor(node);

                if (color == null)
                {
                    continue;
                }

                var colorString = ColorsVectorHelper.ConvertToRGBString(color.Normal);

                var properties = new XElement(Namespaces.Styles("topic-properties"));

                if (node is RootNode || node.Parent is RootNode)
                {
                    properties.Add(new XAttribute(Namespaces.SVG("fill"), colorString));
                }
                else
                {
                    properties.Add(new XAttribute("border-line-color", colorString));
                    properties.Add(new XAttribute("line-color", colorString));
                }

                styles.Add(
                    new XElement(Namespaces.Styles("style"),
                                 new XAttribute("id", "s" + node.Id),
                                 new XAttribute("type", "topic"),
                                 properties));
            }

            xMapStyles.Add(
                new XElement(Namespaces.Styles("xmap-styles"),
                             new XAttribute("version", "2.0"),
                             new XAttribute(XNamespace.Xmlns + "svg", Namespaces.SVGNamespace),
                             styles));
        }