/// <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); }