internal void LoadTemplates() { XmlNodeList blockList = Document.GetElementsByTagName("blocks"); BlockManager = new BlockManager(RootPath); BlockManager.LoadBlocks(blockList[0]); XmlNodeList templateList = Document.GetElementsByTagName("template"); foreach (XmlNode template in templateList) { TemplateDefinition templateDef = TemplateDefinition.LoadCardDefinition(template); templateDef.rootPath = RootPath; TemplateSelector.AddTemplate(templateDef); } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static Image GenerateProxy(BlockManager manager, string rootPath, TemplateDefinition template, Dictionary <string, string> values) { var path = Path.Combine(rootPath, template.src); Image temp = GraphicUtils.LoadImage(path); Bitmap b = ((Bitmap)temp).Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb); //b.MakeTransparent(); //ret.PixelFormat = PixelFormat.Format32bppArgb; using (Graphics graphics = Graphics.FromImage(b)) { foreach (LinkDefinition overlay in template.GetOverLayBlocks(values)) { BlockDefinition block = manager.GetBlock(overlay.Block); if (block.type != "overlay") { continue; } block.src = Path.Combine(rootPath, block.src); GraphicUtils.MergeOverlay(graphics, block); } foreach (LinkDefinition section in template.GetTextBlocks(values)) { List <Property> clonedProps = new List <Property>(); BlockDefinition block = manager.GetBlock(section.Block); if (block.type != "text") { continue; } clonedProps.AddRange(section.NestedProperties); foreach (Property prop in section.NestedProperties) { if (!values.ContainsKey(prop.Name)) { clonedProps.Remove(prop); } if (clonedProps.Contains(prop) && (values[prop.Name] == null || values[prop.Name].Length == 0)) { clonedProps.Remove(prop); } } StringBuilder toWrite = new StringBuilder(); if (clonedProps.Count > 1) { for (int i = 0; i < clonedProps.Count; i++) { string propertyName = clonedProps[i].Name; string format = clonedProps[i].Format.Replace("{}", values[propertyName]); if (i < (clonedProps.Count - 1)) { toWrite.Append(string.Format("{0} {1}", format, section.Separator)); } else { toWrite.Append(format); } } } else { if (clonedProps.Count > 0) { string propertyName = clonedProps[0].Name; string format = clonedProps[0].Format.Replace("{}", values[propertyName]); toWrite.Append(format); } } GraphicUtils.WriteString(graphics, block, toWrite.ToString()); } } return(b); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static Image GenerateProxy(BlockManager manager, string rootPath, TemplateDefinition template, Dictionary <string, string> values, string specialPath) { if (rootPath == null || template == null || template.src == null) { throw new UserMessageException(L.D.Exception__InvalidProxyDefinition); } var path = Path.Combine(rootPath, template.src); Bitmap temp = GraphicUtils.LoadImage(path, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(temp)) { foreach (LinkDefinition overlay in template.GetOverLayBlocks(values)) { BlockDefinition block = null; if (overlay.SpecialBlock != null) { block = overlay.SpecialBlock; if (specialPath == null) { continue; } block.src = specialPath; GraphicUtils.MergeArtOverlay(graphics, block); } else { block = manager.GetBlock(overlay.Block); if (block.type != "overlay") { continue; } block.src = Path.Combine(rootPath, block.src); GraphicUtils.MergeOverlay(graphics, block); } } foreach (LinkDefinition section in template.GetTextBlocks(values)) { List <Property> clonedProps = new List <Property>(); BlockDefinition block = manager.GetBlock(section.Block); if (block.type != "text") { continue; } clonedProps.AddRange(section.NestedProperties); foreach (Property prop in section.NestedProperties) { if (!values.ContainsKey(prop.Name)) { clonedProps.Remove(prop); } if (clonedProps.Contains(prop) && (values[prop.Name] == null || values[prop.Name].Length == 0)) { clonedProps.Remove(prop); } } StringBuilder toWrite = new StringBuilder(); if (clonedProps.Count > 1) { for (int i = 0; i < clonedProps.Count; i++) { string propertyName = clonedProps[i].Name; string format = clonedProps[i].Format.Replace("{}", values[propertyName]); if (i < (clonedProps.Count - 1)) { toWrite.Append(string.Format("{0} {1}", format, section.Separator)); } else { toWrite.Append(format); } } } else { if (clonedProps.Count > 0) { string propertyName = clonedProps[0].Name; string format = clonedProps[0].Format.Replace("{}", values[propertyName]); toWrite.Append(format); } } GraphicUtils.WriteString(graphics, block, toWrite.ToString()); } } return(temp); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static Image GenerateProxy(BlockManager manager, string rootPath, TemplateDefinition template, Dictionary<string,string> values) { var path = Path.Combine(rootPath, template.src); Bitmap temp = GraphicUtils.LoadImage(path,PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(temp)) { foreach (LinkDefinition overlay in template.GetOverLayBlocks(values)) { BlockDefinition block = manager.GetBlock(overlay.Block); if (block.type != "overlay") { continue; } block.src = Path.Combine(rootPath, block.src); GraphicUtils.MergeOverlay(graphics, block); } foreach (LinkDefinition section in template.GetTextBlocks(values)) { List<Property> clonedProps = new List<Property>(); BlockDefinition block = manager.GetBlock(section.Block); if (block.type != "text") { continue; } clonedProps.AddRange(section.NestedProperties); foreach (Property prop in section.NestedProperties) { if (!values.ContainsKey(prop.Name)) { clonedProps.Remove(prop); } if (clonedProps.Contains(prop) && (values[prop.Name] == null || values[prop.Name].Length == 0)) { clonedProps.Remove(prop); } } StringBuilder toWrite = new StringBuilder(); if (clonedProps.Count > 1) { for (int i = 0; i < clonedProps.Count; i++) { string propertyName = clonedProps[i].Name; string format = clonedProps[i].Format.Replace("{}", values[propertyName]); if (i < (clonedProps.Count - 1)) { toWrite.Append(string.Format("{0} {1}", format, section.Separator)); } else { toWrite.Append(format); } } } else { if (clonedProps.Count > 0) { string propertyName = clonedProps[0].Name; string format = clonedProps[0].Format.Replace("{}", values[propertyName]); toWrite.Append(format); } } GraphicUtils.WriteString(graphics, block, toWrite.ToString()); } } return (temp); }
public ProxyDefinition() { TemplateSelector = new TemplateManager(); BlockManager = new BlockManager(); }
public static BlockDefinition DeserializeBlock(BlockManager manager, XmlNode node) { BlockDefinition ret = new BlockDefinition(); ret.Manager = manager; ret.id = node.Attributes["id"].Value; ret.type = node.Attributes["type"].Value; if (node.Attributes["src"] != null) { ret.src = node.Attributes["src"].Value; } foreach (XmlNode prop in node.ChildNodes) { if (SkipNode(prop)) { continue; } if (prop.Name.Equals("location")) { ret.location.x = int.Parse(prop.Attributes["x"].Value); ret.location.y = int.Parse(prop.Attributes["y"].Value); if (prop.Attributes["rotate"] != null) { ret.location.rotate = int.Parse(prop.Attributes["rotate"].Value); } if (prop.Attributes["altrotate"] != null) { ret.location.altrotate = bool.Parse(prop.Attributes["altrotate"].Value); } if (prop.Attributes["flip"] != null) { ret.location.flip = bool.Parse(prop.Attributes["flip"].Value); } } if (prop.Name.Equals("text")) { ret.text.color = ColorTranslator.FromHtml(prop.Attributes["color"].Value); ret.text.size = int.Parse(prop.Attributes["size"].Value); if (prop.Attributes["font"] != null) { string relativePath = prop.Attributes["font"].Value; string rootPath = manager.RootPath; string combined = Path.Combine(rootPath, relativePath); if (File.Exists(combined)) { ret.text.font = relativePath; } } } if (prop.Name.Equals("border")) { ret.border.color = ColorTranslator.FromHtml(prop.Attributes["color"].Value); ret.border.size = int.Parse(prop.Attributes["size"].Value); } if (prop.Name.Equals("wordwrap")) { ret.wordwrap.height = int.Parse(prop.Attributes["height"].Value); ret.wordwrap.width = int.Parse(prop.Attributes["width"].Value); if (prop.Attributes["align"] != null) { ret.wordwrap.align = prop.Attributes["align"].Value; } if (prop.Attributes["valign"] != null) { ret.wordwrap.valign = prop.Attributes["valign"].Value; } if (prop.Attributes["shrinktofit"] != null) { ret.wordwrap.shrinkToFit = bool.Parse(prop.Attributes["shrinktofit"].Value); } } } return(ret); }