public static XElement CreateMargin( XNamespace ns, string elementName, s.Padding padding) { if (padding == null) { return(null); } XElement element = new XElement(ns + elementName); XElement top = CreateWidth(ns, "top", padding.Top); XElement start = CreateWidth(ns, "start", padding.Left); XElement bottom = CreateWidth(ns, "bottom", padding.Bottom); XElement end = CreateWidth(ns, "end", padding.Right); element.Add(top); element.Add(start); element.Add(bottom); element.Add(end); return(element); }
public static XElement CreateBorder( XNamespace ns, string elementName, s.Border border, s.Padding padding) { if (border == null) { return(null); } XElement element = new XElement(ns + elementName); int size = border.Thickness * 8; // eighths of a point int left = (padding?.Left ?? 0) * 8; int bottom = (padding?.Bottom ?? 0) * 8; int right = (padding?.Right ?? 0) * 8; int top = (padding?.Top ?? 0) * 8; int red = (int)((border.Color?.Red ?? 0f) * 255f); int green = (int)((border.Color?.Green ?? 0f) * 255f); int blue = (int)((border.Color?.Blue ?? 0f) * 255f); string color = $"{red:X2}{green:X2}{blue:X2}"; if ((border.Parts & Report.Style.BorderPart.Left) != Report.Style.BorderPart.None) { XElement side = new XElement( ns + "left", new XAttribute(ns + "val", "single"), new XAttribute(ns + "sz", size), new XAttribute(ns + "space", left), new XAttribute(ns + "color", color)); element.Add(side); } if ((border.Parts & Report.Style.BorderPart.Bottom) != Report.Style.BorderPart.None) { XElement side = new XElement( ns + "bottom", new XAttribute(ns + "val", "single"), new XAttribute(ns + "sz", size), new XAttribute(ns + "space", left), new XAttribute(ns + "color", color)); element.Add(side); } if ((border.Parts & Report.Style.BorderPart.Right) != Report.Style.BorderPart.None) { XElement side = new XElement( ns + "right", new XAttribute(ns + "val", "single"), new XAttribute(ns + "sz", size), new XAttribute(ns + "space", left), new XAttribute(ns + "color", color)); element.Add(side); } if ((border.Parts & Report.Style.BorderPart.Top) != Report.Style.BorderPart.None) { XElement side = new XElement( ns + "top", new XAttribute(ns + "val", "single"), new XAttribute(ns + "sz", size), new XAttribute(ns + "space", left), new XAttribute(ns + "color", color)); element.Add(side); } if ((border.Parts & Report.Style.BorderPart.InnerHorizontal) != Report.Style.BorderPart.None) { XElement side = new XElement( ns + "insideH", new XAttribute(ns + "val", "single"), new XAttribute(ns + "sz", size), new XAttribute(ns + "space", left), new XAttribute(ns + "color", color)); element.Add(side); } if ((border.Parts & Report.Style.BorderPart.InnerVertical) != Report.Style.BorderPart.None) { XElement side = new XElement( ns + "insideV", new XAttribute(ns + "val", "single"), new XAttribute(ns + "sz", size), new XAttribute(ns + "space", left), new XAttribute(ns + "color", color)); element.Add(side); } return(element); }