/// <summary> /// Adds a Meta element to the page (in the proper schema sequence) with the /// specified name and value. /// </summary> /// <param name="name"></param> /// <param name="value"></param> public void SetMeta(string name, string value) { var meta = Root.Elements(Namespace + "Meta") .FirstOrDefault(e => e.Attribute("name").Value == name); if (meta == null) { meta = new XElement(Namespace + "Meta", new XAttribute("name", name), new XAttribute("content", value) ); // add into schema sequence... var after = Root.Elements(Namespace + "QuickStyleDef").LastOrDefault(); if (after == null) { after = Root.Elements(Namespace + "TagDef").LastOrDefault(); } if (after == null) { Root.AddFirst(meta); } else { after.AddAfterSelf(meta); } } else { meta.Attribute("content").Value = value; } }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <returns></returns> public Style GetQuickStyle(StandardStyles key) { string name = key.ToName(); var style = Root.Elements(Namespace + "QuickStyleDef") .Where(e => e.Attribute("name").Value == name) .Select(p => new Style(new QuickStyleDef(p))) .FirstOrDefault(); if (style == null) { var quick = key.GetDefaults(); var sibling = Root.Elements(Namespace + "QuickStyleDef").LastOrDefault(); if (sibling == null) { quick.Index = 0; Root.AddFirst(quick.ToElement(Namespace)); } else { quick.Index = int.Parse(sibling.Attribute("index").Value) + 1; sibling.AddAfterSelf(quick.ToElement(Namespace)); } style = new Style(quick); } return(style); }
/// <summary> /// Adds a TagDef to the page and returns its index value. If the tag already exists /// the index is returned with no other changes to the page. /// </summary> /// <param name="symbol">The symbol of the tag</param> /// <param name="name">The name to apply to the new tag</param> /// <returns>The index of the new tag or of the existing tag with the same symbol</returns> public string AddTagDef(string symbol, string name, int tagType = 0) { //<one:TagDef index="0" type="0" symbol="140" fontColor="automatic" highlightColor="none" name="Calculated" /> var tags = Root.Elements(Namespace + "TagDef"); int index = 0; if (tags?.Any() == true) { var tag = tags.FirstOrDefault(e => e.Attribute("symbol").Value == symbol); if (tag != null) { return(tag.Attribute("index").Value); } index = tags.Max(e => int.Parse(e.Attribute("index").Value)) + 1; } Root.AddFirst(new XElement(Namespace + "TagDef", new XAttribute("index", index.ToString()), new XAttribute("type", tagType.ToString()), new XAttribute("symbol", symbol), new XAttribute("fontColor", "automatic"), new XAttribute("highlightColor", "none"), new XAttribute("name", name) )); return(index.ToString()); }
/// <summary> /// Adds the given QuickStyleDef element in the proper document order, just after /// the TagDef elements if there are any /// </summary> /// <param name="def"></param> public void AddQuickStyleDef(XElement def) { var tagdef = Root.Elements(Namespace + "TagDef").LastOrDefault(); if (tagdef == null) { Root.AddFirst(def); } else { tagdef.AddAfterSelf(def); } }
public void AddTagDef(TagDef tagdef) { var tags = Root.Elements(Namespace + "TagDef"); if (tags?.Any() == true) { var tag = tags.FirstOrDefault(e => e.Attribute("symbol").Value == tagdef.Symbol); if (tag != null) { return; } } Root.AddFirst(tagdef); }