public static Image svg(string folder, string name, Size size, Color color) { var key = getKey(name, size, color); if (images.ContainsKey(key)) { return(images[key]); } if (!folder.EndsWith("\\")) { folder = string.Concat(folder, "\\"); } var svg_path = string.Concat(folder, name, ".svg"); try { var svgDoc = SvgDocument.Open(svg_path); var c = new SvgColourServer(color); setColor(svgDoc, c); svgDoc.Width = size.Width; svgDoc.Height = size.Height; var image = svgDoc.Draw(); images[key] = image; return(image); } catch { } if (null_image == null) { null_image = ImageUtil.imageWithColor(Color.Transparent, new Size(10, 10)); } return(null_image); }
public static Image svgByXml(string xml, string name, Size size, Color color) { var key = getKey(name, size, color); if (images.ContainsKey(key)) { return(images[key]); } try { var xDoc = new XmlDocument(); xDoc.LoadXml(xml); var svgDoc = SvgDocument.Open(xDoc); var c = new SvgColourServer(color); setColor(svgDoc, c); svgDoc.Width = size.Width; svgDoc.Height = size.Height; var image = svgDoc.Draw(); images[key] = image; return(image); } catch { } if (null_image == null) { null_image = ImageUtil.imageWithColor(Color.Transparent, new Size(10, 10)); } return(null_image); }
public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); SvgGroup group = new SvgGroup(); SvgColourServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); double width = view.RenderSize.Width; //drawing layer boundaries LayerVM[] layers = columnVm.Layers.ToArray(); double boundary = 0.0; for (int i = 0; i < layers.Length; i++) { LayerVM lVM = layers[i]; if (i < layers.Length - 1) { boundary += lVM.Length; SvgLine line = new SvgLine(); line.Stroke = blackPaint; line.StartX = Helpers.dtos(0.0); line.EndX = Helpers.dtos(width); line.StartY = Helpers.dtos(boundary); line.EndY = Helpers.dtos(boundary); group.Children.Add(line); } var layerSvg = layerPainter.Paint(layers[i], width, lVM.Length); layerSvg.Transforms.Add(new Svg.Transforms.SvgTranslate(0.0f, (float)(boundary - lVM.Length))); group.Children.Add(layerSvg); } result.SVG = group; return(result); }
public RenderedSvg RenderHeader() { RenderedSvg result = new RenderedSvg(); SvgPaintServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); string[] spans = vm.Heading.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); SvgText text = new SvgText(); float fontSize = 10.0f; foreach (var span in spans) { SvgTextSpan tspan = new SvgTextSpan(); tspan.Text = span; tspan.FontSize = new SvgUnit(fontSize); tspan.Dy.Add(Helpers.dtos(fontSize * 1.2)); tspan.X.Add(0); tspan.Fill = blackPaint; text.Children.Add(tspan); } //text.Transforms.Add(new Svg.Transforms.SvgTranslate(0, (float)(- (fontSize * 1.2) * spans.Length * 0.5))); result.RenderedSize = headerView.RenderSize; result.SVG = text; return(result); }
private static void setColor(SvgElement svgEle, SvgColourServer color) { svgEle.Fill = color; foreach (SvgElement sub in svgEle.Children) { setColor(sub, color); } }
private void FillElement(SvgElement elem, SvgColourServer c) { if (!elem.Fill.Equals(new SvgColourServer(Color.Transparent))) { elem.Fill = c; } elem.Stroke = c; foreach (SvgElement elem2 in elem.Children) { FillElement(elem2, c); } }
private void setTextlist(SvgDocument svg, ResponseValue responseVar, Textlist textlist, ref SvgRectangle rectangle, ref SvgTextSpan svgText) { int textId = int.Parse(responseVar.value.ToString()); SvgColourServer rectColor = new SvgColourServer(Color.FromName(textlist.items[textId].bgColor)); rectangle.Fill = rectColor; svgText.Text = textlist.items[textId].value; SvgColourServer textColor = new SvgColourServer(Color.FromName(textlist.items[textId].textColor)); svgText.Fill = textColor; }
/// ************************************************************************************************ /// <summary> /// Creates Dictionary with Bitmaps of the same height from SVG sources /// </summary> /// <param name="icons">Dictionary with icons</param> /// <param name="fontSize">Height of icons</param> /// <param name="foregroundColor1">Foreground color for main text, it is used to change color of some icons</param> /// <param name="foregroundColor2">Foreground color for additional text, it is used to change color of some icons</param> /// <returns>true if Dictionary successfully created</returns> public static bool CreateIconsDictionaryFromSVG(out Dictionary <string, BitmapImage> icons, double fontSize, string foregroundColor1, string foregroundColor2, string foregroundColor3) { bool result = true; icons = new Dictionary <string, BitmapImage>(); System.Windows.Media.Color color1 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(foregroundColor1); System.Windows.Media.Color color2 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(foregroundColor2); System.Windows.Media.Color color3 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(foregroundColor3); foregroundColor[0] = new SvgColourServer(System.Drawing.Color.FromArgb(color1.R, color1.G, color1.B)); foregroundColor[1] = new SvgColourServer(System.Drawing.Color.FromArgb(color2.R, color2.G, color2.B)); foregroundColor[2] = new SvgColourServer(System.Drawing.Color.FromArgb(color3.R, color3.G, color3.B)); string[] svgNames = GetResourcesNamesFromFolder("SVGIcons"); foreach (string svgName in svgNames) { try { string key = Path.GetFileNameWithoutExtension(svgName).ToUpperInvariant(); bool changeColor1 = Array.IndexOf(FollowForegroundIconKey1, key) >= 0; bool changeColor2 = Array.IndexOf(FollowForegroundIconKey2, key) >= 0; bool changeColor3 = Array.IndexOf(FollowForegroundIconKey3, key) >= 0; BitmapImage bi = GetBitmapFromSVG(new Uri(SvgPath + svgName), fontSize, changeColor1 || changeColor2 || changeColor3, changeColor1 ? 0 : (changeColor2 ? 1 : 2)); icons.Add(key, bi); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); result = false; break; } catch (UriFormatException ex2) { Console.WriteLine(ex2.Message); result = false; break; } } return(result); }
private void BtnLoad_Click(object sender, RoutedEventArgs e) { var red = new SvgColourServer(System.Drawing.Color.Red); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "svg文件|*.svg"; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog().GetValueOrDefault()) { string path = openFileDialog.FileName; SvgDocument svgdoc = SvgDocument.Open(path); var lines = svgdoc.Children.FindSvgElementsOf <SvgLine>(); foreach (var item in lines) { item.Stroke = red; } svgdoc.Draw().Save("tmp.png", System.Drawing.Imaging.ImageFormat.Png); BitmapImage bitmap = GetBitmap("tmp.png"); img.Source = bitmap; } }
public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); double width = result.RenderedSize.Width; SvgGroup linesGroup = new SvgGroup(); SvgColourServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); int minRank = int.MaxValue; LayerBoundary[] boundaries = vm.Boundaries.OrderBy(b => b.Level).ToArray(); var rank = boundaries.Select(b => b.Rank).Min(); for (int i = 0; i < boundaries.Length; i++) { LayerBoundary boundary = boundaries[i]; SvgLine line = new SvgLine(); line.StartX = Helpers.dtos(0.0); line.EndX = Helpers.dtos(width); line.StartY = Helpers.dtos(boundary.Level); line.EndY = Helpers.dtos(boundary.Level); line.Stroke = blackPaint; linesGroup.Children.Add(line); minRank = Math.Min(minRank, boundary.Rank); string textStr = string.Format("{0}", boundary.Numbers[rank]); //putting layer number as well SvgText text2 = new SvgText(textStr); text2.Transforms.Add(new Svg.Transforms.SvgTranslate(labelXoffset, (float)(boundary.Level + labelYoffset))); text2.FontSize = Helpers.dtos(10.0); text2.Fill = blackPaint; linesGroup.Children.Add(text2); } result.SVG = linesGroup; return(result); }
private void setAgeBar(SvgDocument svg, ResponseValue responseValue, AgeBar ageBar, ref SvgRectangle rectangle, ref SvgRectangle defaultRectangle, bool vertical = false) { float value = float.Parse(responseValue.value.ToString()); if (vertical == false) { var widthType = defaultRectangle.Width.Type; float widthValue = (defaultRectangle.Width.Value / ageBar.maxAge) * value; SvgUnit width = new SvgUnit(widthType, widthValue); if (widthValue > ageBar.firstLimit && widthValue < ageBar.secLimit) { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.firstColor)); rectangle.Fill = rectangleColor; } else if (widthValue > ageBar.secLimit) { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.secondColor)); rectangle.Fill = rectangleColor; } else { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.thirdColor)); rectangle.Fill = rectangleColor; } rectangle.Width = width; } else { var c = Color.FromName(ageBar.thirdColor); //initial height is missing in config SvgColourServer rectangleColor = new SvgColourServer(c); rectangle.Fill = rectangleColor; var heightType = defaultRectangle.Height.Type; float heightValue = (defaultRectangle.Height.Value / ageBar.maxAge) * value; SvgUnit height = new SvgUnit(heightType, heightValue); rectangle.Height = heightValue; } }
public override void Draw(SvgDocument Svg, FlagMainPattern flag, PointF pos, float size, Color c, Random R) { string[] files = Directory.GetFiles(Path.GetDirectoryName(Program.SavePath) + "/../../../RelatedProjects/FlagGeneration/Resources/CoatOfArms"); string chosenPath = files[R.Next(files.Length)]; SvgDocument prefab = SvgDocument.Open(chosenPath); prefab.Width = size; prefab.Height = size; prefab.X = pos.X - size / 2; prefab.Y = pos.Y - size / 2; SvgColourServer colServ = new SvgColourServer(c); prefab.Fill = colServ; prefab.Stroke = colServ; foreach (SvgElement elem in prefab.Children) { FillElement(elem, colServ); } Svg.Children.Add(prefab); }
//public void AfficherTraitsClassique() //{ // StrokeCollection strokeCollections = Traits.Clone(); // StylusPointCollection points = new StylusPointCollection(); // foreach (Stroke stroke in strokeCollections) // { // points.Add(stroke.StylusPoints); // StylusPointCollection first = new StylusPointCollection(); // first.Add(points[0]); // Stroke newStroke = new Stroke(first); // DispatcherTimer timer = new DispatcherTimer(); // timer.Interval = TimeSpan.FromMilliseconds(10); // timer.Start(); // int index = 0; // timer.Tick += (s, a) => // { // newStroke.StylusPoints.Insert(index, points[index]); // if (!NouveauxTraits.Contains(newStroke)) // { // NouveauxTraits.Add(newStroke); // } // index++; // if (index >= points.Count) timer.Stop(); // }; // }; //} private void ConvertDrawingToSVG(object sender) { var svg = new SvgDocument(); var colorServer = new SvgColourServer(System.Drawing.Color.Black); var group = new SvgGroup { Fill = colorServer, Stroke = colorServer }; svg.Children.Add(group); foreach (var stroke in Traits) { var geometry = stroke.GetGeometry(stroke.DrawingAttributes).GetOutlinedPathGeometry(); var s = XamlWriter.Save(geometry); if (!string.IsNullOrEmpty(s)) { var element = XElement.Parse(s); var data = element.Attribute("Figures")?.Value; if (!string.IsNullOrEmpty(data)) { group.Children.Add(new SvgPath { PathData = SvgPathBuilder.Parse(data), Fill = colorServer, Stroke = colorServer }); } } } Mediator.Notify("GoToNewDrawingConfirmation", ""); }
public static string ConvertDrawingToSVG(StrokeCollection traits) { var svg = new SvgDocument(); var colorServer = new SvgColourServer(System.Drawing.Color.Black); var group = new SvgGroup { Fill = colorServer, Stroke = colorServer }; svg.Children.Add(group); foreach (var stroke in traits) { var geometry = stroke.GetGeometry(stroke.DrawingAttributes).GetOutlinedPathGeometry(); var s = XamlWriter.Save(geometry); if (!string.IsNullOrEmpty(s)) { var element = XElement.Parse(s); var data = element.Attribute("Figures")?.Value; if (!string.IsNullOrEmpty(data)) { group.Children.Add(new SvgPath { PathData = SvgPathBuilder.Parse(data), Fill = colorServer, Stroke = colorServer }); } } } return(group.GetXML()); }
private static SvgLine Line(float startX, float startY, float endX, float endY, SvgColourServer color) { return(new SvgLine { StartX = startX.Px(), StartY = startY.Px(), EndX = endX.Px(), EndY = endY.Px(), Stroke = color, StrokeWidth = Units.Mm(Constants.Kerf) }); }
private SvgColourServer ChangeAlphaColor(SvgColourServer color, int alpha) { var replaceColor = Color.FromArgb(alpha, color.Colour); return(new SvgColourServer(replaceColor)); }
private void BtnSVG_Click(object sender, RoutedEventArgs e) { var blue = new SvgColourServer(System.Drawing.Color.Blue); var yellow = new SvgColourServer(System.Drawing.Color.Yellow); var white = new SvgColourServer(System.Drawing.Color.White); var black = new SvgColourServer(System.Drawing.Color.Black); SvgDocument svgdoc = new SvgDocument(); svgdoc.Width = new SvgUnit(SvgUnitType.Pixel, 500); svgdoc.Height = new SvgUnit(SvgUnitType.Pixel, 500); svgdoc.ViewBox = new SvgViewBox(0, 0, 500, 500); var group = new SvgGroup(); svgdoc.Children.Add(group); var dd = new SvgFontStyleConverter(); group.Children.Add(new SvgText { Text = "华青仪表", X = new SvgUnitCollection { new SvgUnit(SvgUnitType.Pixel, 100) }, Y = new SvgUnitCollection { new SvgUnit(SvgUnitType.Pixel, 100) }, FontSize = new SvgUnit(SvgUnitType.Point, 20), Fill = black, Font = "黑体" }); SvgLine line = new SvgLine(); line.StartX = new SvgUnit(SvgUnitType.Pixel, 10); line.StartY = new SvgUnit(SvgUnitType.Pixel, 110); line.EndX = new SvgUnit(SvgUnitType.Pixel, 400); line.EndY = new SvgUnit(SvgUnitType.Pixel, 400); SvgCircle circle = new SvgCircle() { CenterX = 250, CenterY = 250, Stroke = blue, Radius = 50, StrokeWidth = new SvgUnit(SvgUnitType.Pixel, 5) }; group.Children.Add(circle); line.Stroke = blue; line.Fill = blue; line.StrokeWidth = new SvgUnit(SvgUnitType.Pixel, 5); group.Children.Add(line); #region 使用时,svg文档与数据库 /*注:XmlDocument读取svg文档内容,保存数据库(), * 然后SvgDocument.FromSvg<SvgDocument>()读取SvgDocument,在提取里面的<g>标签, * 给<g>加上平移变换translate即可实现将现有svg文档导入另外一个文档*/ //string strDoc = ""; //XmlDocument xmldoc = new XmlDocument(); //xmlDoc.Load(openSvgFile.FileName); //strDoc = xmlDoc.InnerXml; //SaveDB(strDoc); //strDoc = ReadFromDB(); //xmldoc.LoadXml(strDoc); //var dd = SvgDocument.FromSvg<SvgDocument>(strDoc); //var g = dd.Children.FindSvgElementOf<SvgGroup>(); #endregion //加载表盘测试.svg,将其中的group 加入到当前svg SvgDocument svgtest = SvgDocument.Open("表盘测试.svg"); var groupstest = svgtest.Children.FindSvgElementsOf <SvgGroup>(); foreach (var g in groupstest) { g.Transforms.Add(new Svg.Transforms.SvgTranslate(50, 50)); group.Children.Add(g); } //string strPath = @"<path transform=""translate(-20,0)"" fill-rule=""evenodd"" clip-rule=""evenodd"" fill=""none"" stroke=""#000000"" stroke-width=""1.4173"" stroke-miterlimit=""2.4142"" d="" //M217.274,209.852c4.294,0,7.796,3.502,7.796,7.795c0,4.295-3.502,7.797-7.796,7.797s-7.795-3.502-7.795-7.797 //C209.479,213.354,212.98,209.852,217.274,209.852L217.274,209.852z""/>"; /* * <path transform="translate(-20,0)" fill-rule="evenodd" clip-rule="evenodd" fill="none" stroke="#000000" stroke-width="1.4173" stroke-miterlimit="2.4142" d=" * M217.274,209.852c4.294,0,7.796,3.502,7.796,7.795c0,4.295-3.502,7.797-7.796,7.797s-7.795-3.502-7.795-7.797 * C209.479,213.354,212.98,209.852,217.274,209.852L217.274,209.852z"/> */ //var b = SvgPathBuilder.Parse(@"M217.274,209.852c4.294,0,7.796,3.502,7.796,7.795c0,4.295-3.502,7.797-7.796,7.797s-7.795-3.502-7.795-7.797 // C209.479, 213.354, 212.98, 209.852, 217.274, 209.852L217.274, 209.852z"); //SvgPath p = new SvgPath(); //p.PathData = b; //group.Children.Add(p); svgdoc.Write("456.svg"); svgdoc.Draw().Save("456.png", System.Drawing.Imaging.ImageFormat.Png); MessageBox.Show("456.svg + 456.png"); BitmapImage bitmap = GetBitmap("456.png"); img.Source = bitmap; }
public static SvgDocument Generate(ISvgRenderableColumn[] columns, ILegendGroup[] legend) { //generating headers SvgGroup headerGroup = new SvgGroup(); SvgPaintServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); double horizontalOffset = 0.0; double headerHeight = 0; for (int i = 0; i < columns.Length; i++) { RenderedSvg heading = columns[i].RenderHeader(); SvgRectangle rect = new SvgRectangle(); headerHeight = heading.RenderedSize.Height; rect.Width = Helpers.dtos(heading.RenderedSize.Width); rect.Height = Helpers.dtos(heading.RenderedSize.Height); rect.X = Helpers.dtos(horizontalOffset); rect.Y = Helpers.dtos(0.0); rect.Stroke = blackPaint; heading.SVG.Transforms.Add(new SvgTranslate((float)(horizontalOffset + heading.RenderedSize.Width * 0.5), (float)heading.RenderedSize.Height * 0.9f)); heading.SVG.Transforms.Add(new SvgRotate((float)-90.0)); headerGroup.Children.Add(rect); headerGroup.Children.Add(heading.SVG); horizontalOffset += heading.RenderedSize.Width; } //generating columns SvgGroup columnsGroup = new SvgGroup(); double columnHeight = 0.0; horizontalOffset = 0.0; columnsGroup.Transforms.Add(new SvgTranslate(0.0f, (float)headerHeight)); for (int i = 0; i < columns.Length; i++) { RenderedSvg column = columns[i].RenderColumn(); SvgRectangle rect = new SvgRectangle(); columnHeight = column.RenderedSize.Height; rect.Width = Helpers.dtos(column.RenderedSize.Width); rect.Height = Helpers.dtos(column.RenderedSize.Height); rect.X = Helpers.dtos(horizontalOffset); rect.Y = Helpers.dtos(0.0); rect.Stroke = blackPaint; column.SVG.Transforms.Add(new SvgTranslate((float)(horizontalOffset))); columnsGroup.Children.Add(rect); columnsGroup.Children.Add(column.SVG); horizontalOffset += column.RenderedSize.Width; } //generating legend group SvgGroup legendGroup = new SvgGroup(); const float legendYGap = 30.0f; const float legendXOffset = 10.0f; legendGroup.Transforms.Add(new SvgTranslate(legendXOffset, Helpers.dtos(headerHeight + columnHeight + legendYGap))); const float titleYoffset = 60.0f; const float itemsYoffset = 20.0f; const float itemYgap = 20.0f; const float interGroupYgap = 15.0f; const float itemImageWidth = 64.0f; const float itemImageHeight = 32.0f; const float descrXoffset = 150.0f; SvgText legendTitle = new SvgText("Условные обозначения"); legendTitle.FontSize = 22; legendTitle.Fill = new SvgColourServer(System.Drawing.Color.Black); legendTitle.Transforms.Add(new SvgTranslate(30.0f, Helpers.dtos(titleYoffset * 0.25f))); legendGroup.Children.Add(legendTitle); float currGroupOffset = 0.0f; int k = 0; foreach (ILegendGroup group in legend) { //title SvgText groupTitle = new SvgText(group.GroupName); groupTitle.FontSize = new SvgUnit((float)18); groupTitle.Fill = new SvgColourServer(System.Drawing.Color.Black); groupTitle.Transforms.Add(new SvgTranslate(0.0f, currGroupOffset + titleYoffset)); legendGroup.Children.Add(groupTitle); //items var items = group.Items; int j = 0; SvgElement[] fragments = items.Select(item => item.GetPresentation(itemImageWidth, itemImageHeight)).ToArray(); foreach (var item in items) { if (fragments[j] == null) { continue; } float yOffset = currGroupOffset + titleYoffset + itemsYoffset + j * (itemYgap + itemImageHeight); if (fragments[j] is SvgFragment) { SvgFragment fragment = (SvgFragment)fragments[j]; fragment.X = 0; fragment.Y = yOffset; } else { fragments[j].Transforms.Add(new SvgTranslate(0, yOffset)); } legendGroup.Children.Add(fragments[j]); SvgText text = new SvgText(item.Description); text.FontSize = new SvgUnit((float)14); text.Fill = new SvgColourServer(System.Drawing.Color.Black); text.Transforms.Add(new SvgTranslate(descrXoffset, yOffset + itemImageHeight * 0.5f)); legendGroup.Children.Add(text); j++; } currGroupOffset += titleYoffset + itemsYoffset + (itemYgap + itemImageHeight) * items.Length + interGroupYgap; k++; } //gathering definitions SvgDefinitionList allDefs = new SvgDefinitionList(); for (int i = 0; i < columns.Length; i++) { SvgDefinitionList defs = columns[i].Definitions; foreach (SvgPatternServer def in defs.Children) { //overridings tile size allDefs.Children.Add(def); } } SvgDocument result = new SvgDocument(); result.Children.Add(allDefs); result.Width = Helpers.dtos(horizontalOffset); result.Height = Helpers.dtos((headerHeight + columnHeight + legendYGap + currGroupOffset)); result.Fill = new SvgColourServer(System.Drawing.Color.White); result.Children.Add(headerGroup); result.Children.Add(columnsGroup); result.Children.Add(legendGroup); return(result); }
public void GenerateSVG() { SvgDocument doc = new SvgDocument(); doc.FontSize = 16; SvgColourServer blackPainter = new SvgColourServer(Color.Black); SvgColourServer whitePainter = new SvgColourServer(Color.White); SvgColourServer grayPainter = new SvgColourServer(Color.Gray); SvgColourServer greenPainter = new SvgColourServer(Color.LightGreen); int round_gap = 50; int matchup_width = 400; int matchup_height = 150; int matchup_team_x_offset = 20; int matchup_team_y_offset = 50; int matchup_team_font_size = 36; int matchup_vs_font_size = 24; int matchup_offset_y = 0; int matchup_gap_y = 10; for (int r_i = 0; r_i < Rounds.Count; r_i++) { Round r = Rounds[r_i]; Console.WriteLine("Round {0} Matches: ", r.ID); //Calculate matchup gap int round_x_offset = r_i * (matchup_width + round_gap); for (int m_i = 0; m_i < r.Matchups.Count; m_i++) { Matchup m = r.Matchups[m_i]; int round_y_offset = m_i * (matchup_height + matchup_gap_y) + matchup_offset_y; //Draw Rectangle per Matchup SvgRectangle rec = new SvgRectangle(); rec.X = round_x_offset; rec.Y = round_y_offset; rec.Width = matchup_width; rec.Height = matchup_height; rec.Stroke = blackPainter; rec.StrokeWidth = 2; if (!m.IsFinished) { rec.Fill = whitePainter; } else { rec.Fill = greenPainter; } doc.Children.Add(rec); //Team 1 Text string team_text = "TBD"; string team_id = ""; if (m.Team1 != null) { if (m.Team1.IsDummy) { team_text = "-"; } else { team_text = m.Team1.Name; team_id = m.Team1.ID.ToString("00"); } } //Add Text //Τeam ID SvgText t1 = new SvgText(team_id); t1.FontSize = matchup_team_font_size; t1.X.Add(round_x_offset + matchup_team_x_offset - 10); t1.Y.Add(round_y_offset + matchup_team_y_offset); doc.Children.Add(t1); //Τeam Name t1 = new SvgText(team_text); if (m.Team1 == m.Winner && m.Winner != null) { t1.FontWeight = SvgFontWeight.Bold; } t1.FontSize = matchup_team_font_size; t1.X.Add(round_x_offset + 50 + matchup_team_x_offset); t1.Y.Add(round_y_offset + matchup_team_y_offset); doc.Children.Add(t1); SvgText t3 = new SvgText("vs"); t3.FontSize = matchup_vs_font_size; t3.X.Add(round_x_offset + matchup_team_x_offset); t3.Y.Add(round_y_offset + 5 + matchup_height / 2.0f); doc.Children.Add(t3); //Horizontal Matchup Splitter Line Part 1 //Add horizontal line SvgLine hl1 = new SvgLine(); hl1.Stroke = blackPainter; hl1.StrokeWidth = 5; hl1.StrokeOpacity = 1.0f; hl1.FillOpacity = 1.0f; hl1.StartX = round_x_offset + matchup_team_x_offset + 40; hl1.StartY = round_y_offset + matchup_height / 2.0f; hl1.EndX = round_x_offset + matchup_width; hl1.EndY = hl1.StartY; doc.Children.Add(hl1); //Vertical Line on the splitter SvgLine vl1 = new SvgLine(); vl1.Stroke = blackPainter; vl1.StrokeWidth = 5; vl1.StrokeOpacity = 1.0f; vl1.FillOpacity = 1.0f; vl1.StartX = hl1.StartX; vl1.StartY = hl1.StartY; vl1.EndX = vl1.StartX; vl1.EndY = hl1.StartY - matchup_height / 2.0f; doc.Children.Add(vl1); SvgLine vl2 = new SvgLine(); vl2.Stroke = blackPainter; vl2.StrokeWidth = 5; vl2.StrokeOpacity = 1.0f; vl2.FillOpacity = 1.0f; vl2.StartX = hl1.StartX; vl2.StartY = hl1.StartY; vl2.EndX = vl1.StartX; vl2.EndY = hl1.StartY + matchup_height / 2.0f; doc.Children.Add(vl2); //Team 2 Text team_text = "TBD"; team_id = ""; if (m.Team2 != null) { if (m.Team2.IsDummy) { team_text = "-"; } else { team_text = m.Team2.Name; team_id = m.Team2.ID.ToString("00"); } } //Τeam ID SvgText t2 = new SvgText(team_id); t2.FontSize = matchup_team_font_size; t2.X.Add(round_x_offset + matchup_team_x_offset - 10); t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset); doc.Children.Add(t2); t2 = new SvgText(team_text); if (m.Team2 == m.Winner && m.Winner != null) { t2.FontWeight = SvgFontWeight.Bold; } t2.FontSize = matchup_team_font_size; t2.X.Add(round_x_offset + 50 + matchup_team_x_offset); t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset); doc.Children.Add(t2); //Draw Matchup Connector to next Matchup if (r_i != Rounds.Count - 1) { //Add horizontal line SvgLine l = new SvgLine(); l.Stroke = grayPainter; l.StrokeWidth = 5; l.StrokeOpacity = 1.0f; l.FillOpacity = 1.0f; l.StartX = round_x_offset + matchup_width; l.StartY = round_y_offset + matchup_height / 2.0f; l.EndX = l.StartX + round_gap / 2.0f; l.EndY = l.StartY; doc.Children.Add(l); //Vertical Line SvgLine l1 = new SvgLine(); l1.Stroke = grayPainter; l1.StrokeWidth = 5; l1.StrokeOpacity = 1.0f; l1.FillOpacity = 1.0f; l1.StartX = l.EndX; l1.StartY = l.EndY; l1.EndX = l.EndX; if (m_i % 2 == 0) { l1.EndY = l.StartY + (matchup_height + matchup_gap_y) / 2.0f; } else { l1.EndY = l.StartY - (matchup_height + matchup_gap_y) / 2.0f; } doc.Children.Add(l1); //Last horizontal line SvgLine l2 = new SvgLine(); l2.Stroke = grayPainter; l2.StrokeWidth = 5; l2.StrokeOpacity = 1.0f; l2.FillOpacity = 1.0f; l2.StartX = l1.EndX; l2.StartY = l1.EndY; l2.EndX = l1.EndX + round_gap / 2.0f; l2.EndY = l1.EndY; doc.Children.Add(l2); } } //Update Matchup gaps and offsets matchup_offset_y += (matchup_height + matchup_gap_y) / 2; matchup_gap_y = 2 * (matchup_gap_y + matchup_height) - matchup_height; } Bitmap img = doc.Draw(); img.Save("bracket.png"); img.Dispose(); }
public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); SvgGroup group = new SvgGroup(); SvgColourServer blackPiant = new SvgColourServer(System.Drawing.Color.Black); //first adding ticks double tickStep = Math.Pow(10.0, TickDepthResolutionOrder); double tickStart; if (TickDepthResolutionOrder <= 0) { tickStart = Math.Round(vm.UpperBound, -TickDepthResolutionOrder); } else { tickStart = Math.Round(vm.UpperBound / tickStep) * tickStep; } if (tickStart < vm.UpperBound) { tickStart += tickStart; } double tick = tickStart; //How many WPF units in 1 real meter of depth double depthScaleFactor = vm.ColumnHeight / (vm.LowerBound - vm.UpperBound); Func <double, double> depthToY = depth => (depth - vm.UpperBound) * depthScaleFactor; while (tick < vm.LowerBound) { SvgLine line = new SvgLine(); line.Stroke = blackPiant; line.StartX = Helpers.dtos(0); line.EndX = Helpers.dtos(labelXoffset); line.StartY = Helpers.dtos(depthToY(tick)); line.EndY = Helpers.dtos(depthToY(tick)); group.Children.Add(line); tick += tickStep; //SvgText text = new SvgText(string.Format("{0}",tick)); //text.Transforms.Add(new Svg.Transforms.SvgTranslate()); } //now adding labels double labelStep = Math.Pow(10.0, LabelDepthResolutionOrder); double labelStart; if (LabelDepthResolutionOrder <= 0) { labelStart = Math.Round(vm.UpperBound, -LabelDepthResolutionOrder); } else { labelStart = Math.Round(vm.UpperBound / labelStep) * labelStep; } if (labelStart < vm.UpperBound) { labelStart += labelStep; } double label = labelStart; while (label < vm.LowerBound) { SvgText text = new SvgText(string.Format("{0}", label)); text.Transforms.Add(new Svg.Transforms.SvgTranslate(labelXoffset, (float)depthToY(label) + labelYoffset)); text.Fill = blackPiant; text.FontSize = Helpers.dtos(labelSize); group.Children.Add(text); label += labelStep; } result.SVG = group; return(result); }
public void DrawCorner() { Bitmap Image; if (true) { Image = _svg.Draw(); LuminanceSource source = new BitmapLuminanceSource(Image); var binBitmap = new BinaryBitmap(new HybridBinarizer(source)); var result = new MultiFormatReader().decode(binBitmap); if (result != null) { var moduleSize = ((FinderPattern)result.ResultPoints[0]).EstimatedModuleSize; var fill = true; var outterFill = new SvgColourServer(Color.Black); var backFill = new SvgColourServer(Color.White); var innerFill = new SvgColourServer(Color.Black); for (var i = 0; i < 3; ++i) { if (!(result.ResultPoints[i] is FinderPattern)) { continue; } var p = new PointF(result.ResultPoints[i].X, result.ResultPoints[i].Y); var m = moduleSize * 3.5f; var r1 = new RectangleF(p.X - m, p.Y - m, m * 2, m * 2); m = moduleSize * 2.5f; var r2 = new RectangleF(p.X - m, p.Y - m, m * 2, m * 2); m = moduleSize * 1.5f; var r3 = new RectangleF(p.X - m, p.Y - m, m * 2, m * 2); var qry = SvgQrcodeGroup.Children.Where( r => r is SvgRectangle && r1.IntersectsWith(((SvgRectangle)r).Bounds)) .ToList(); foreach (var c in qry) { SvgQrcodeGroup.Children.Remove(c); } SvgVisualElement c1, c2; PositionPatterns POP = PositionPatterns.RoundedRect; PositionPatterns PIP = PositionPatterns.RoundedRect; switch (POP) { case PositionPatterns.RoundedRect: var rect2 = new SvgRectangle { X = r1.X, Y = r1.Y, Width = r1.Width, Height = r1.Height }; SvgQrcodeGroup.Children.Add(rect2); var rect = rect2; rect.CornerRadiusX = r1.Width * 0.2f; rect.CornerRadiusY = r1.Height * 0.2f; c1 = rect; var rect3 = new SvgRectangle { X = r2.X, Y = r2.Y, Width = r2.Width, Height = r2.Height }; SvgQrcodeGroup.Children.Add(rect3); var rect1 = rect3; rect1.CornerRadiusX = r2.Width * 0.2f; rect1.CornerRadiusY = r2.Height * 0.2f; c2 = rect1; break; case PositionPatterns.Circle: var c = new SvgCircle { CenterX = r1.X + r1.Width / 2, CenterY = r1.Y + r1.Height / 2, Radius = r1.Width / 2 }; SvgQrcodeGroup.Children.Add(c); c1 = c; var c3 = new SvgCircle { CenterX = r2.X + r2.Width / 2, CenterY = r2.Y + r2.Height / 2, Radius = r2.Width / 2 }; SvgQrcodeGroup.Children.Add(c3); c2 = c3; break; default: var rect4 = new SvgRectangle { X = r1.X, Y = r1.Y, Width = r1.Width, Height = r1.Height }; SvgQrcodeGroup.Children.Add(rect4); c1 = rect4; var rect5 = new SvgRectangle { X = r2.X, Y = r2.Y, Width = r2.Width, Height = r2.Height }; SvgQrcodeGroup.Children.Add(rect5); c2 = rect5; break; } if (fill) { c1.Fill = outterFill; } c2.Fill = backFill; switch (PIP) { case PositionPatterns.RoundedRect: var rect1 = new SvgRectangle { X = r3.X, Y = r3.Y, Width = r3.Width, Height = r3.Height }; SvgQrcodeGroup.Children.Add(rect1); var rect = rect1; rect.CornerRadiusX = r3.Width * 0.2f; rect.CornerRadiusY = r3.Height * 0.2f; c1 = rect; break; case PositionPatterns.Circle: var c = new SvgCircle { CenterX = r3.X + r3.Width / 2, CenterY = r3.Y + r3.Height / 2, Radius = r3.Width / 2 }; SvgQrcodeGroup.Children.Add(c); c1 = c; break; default: var rect2 = new SvgRectangle { X = r3.X, Y = r3.Y, Width = r3.Width, Height = r3.Height }; SvgQrcodeGroup.Children.Add(rect2); c1 = rect2; break; } if (fill) { c1.Fill = innerFill; } } } } }
internal static XColor Color2XColor(SvgColourServer color) { return(color != null?XColor.FromArgb(color.Colour.ToArgb()) : XColors.Black); }
/// <summary> /// Converts an SVGDocument into lines of Turing Code. Syntax in OpenTuring v2.0 /// </summary> /// <param name="file">The SvgDocument</param> /// <returns>Turing Code</returns> public static string toTuring(SvgDocument file) { gH = (int)file.Height.Value; gW = (int)file.Width.Value; StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("setscreen (\"graphics: {0}; {1}\")", gW, gH)); sb.AppendLine("var c1: int % Stroke colour always"); sb.AppendLine("var c2: int % Fill colour always"); // Reduce the number of unnecessary repetitions of the usage of c1 & c2 string cacheC1 = ""; string cacheC2 = ""; // Loop through children and find the type of the SVG Element foreach (var c in file.Children) { #region Lines if (c is SvgLine) //Line { var line = c as SvgLine; SvgColourServer sv = line.Stroke as SvgColourServer; if (cacheC1 != string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sv.Colour.R / 255f, sv.Colour.G / 255f, sv.Colour.B / 255f)) { cacheC1 = string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sv.Colour.R / 255f, sv.Colour.G / 255f, sv.Colour.B / 255f); sb.AppendLine(cacheC1); } if (sv.ToString() != "none") { sb.AppendLine(drawLine((int)line.StartX.Value, (int)line.StartY.Value, (int)line.EndX.Value, (int)line.EndY.Value, (int)line.StrokeWidth.Value, getColor(sv.Colour.Name, false))); } } #endregion #region Rectangles else if (c is SvgRectangle) //Rectangle { var rect = c as SvgRectangle; int x1 = (int)rect.X.Value; int y1 = gH - ((int)rect.Y.Value - (int)rect.Height.Value); int x2 = x1 + (int)rect.Width.Value; int y2 = y1 + (int)rect.Height.Value; var sColor = rect.Stroke as SvgColourServer; var fColor = rect.Fill as SvgColourServer; // Get the colour and decide if we should use RGB or Turing (text) colours if ((sColor.ToString() != "none") && !isTuringColor(sColor.Colour.ToString())) { if (cacheC1 != string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sColor.Colour.R / 255f, sColor.Colour.G / 255f, sColor.Colour.B / 255f)) { cacheC1 = string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sColor.Colour.R / 255f, sColor.Colour.G / 255f, sColor.Colour.B / 255f); sb.AppendLine(cacheC1); } } if ((fColor.ToString() != "none") && !isTuringColor(fColor.Colour.ToString())) { if (cacheC2 != string.Format("c2 := RGB.AddColour({0}, {1}, {2})", fColor.Colour.R / 255f, fColor.Colour.G / 255f, fColor.Colour.B / 255f)) { cacheC2 = string.Format("c2 := RGB.AddColour({0}, {1}, {2})", fColor.Colour.R / 255f, fColor.Colour.G / 255f, fColor.Colour.B / 255f); sb.AppendLine(cacheC2); } } // Check and apply the stroke if ((rect.StrokeWidth.Value > 0) && (sColor.ToString() != "none") && (!sColor.Colour.IsEmpty) && (sColor.Colour.A > 0)) { int width = (int)rect.StrokeWidth.Value; sb.AppendLine(drawFillOval(x1 - width, y1 - width, x2 + width, y2 + width, getColor(sColor.Colour.ToString(), false))); } // Check if it is filled if ((fColor.ToString() != "none") && (!fColor.Colour.IsEmpty) && (fColor.Colour.A > 0)) { sb.AppendLine(drawFillBox(x1, y1, x2, y2, getColor(fColor.Colour.Name, true))); } else { sb.AppendLine(drawBox(x1, y1, x2, y2, getColor(sColor.Colour.Name, false))); } } //End if #endregion #region Paths // Thanks to Nathan Lo for helping me in this bit of horror // A sh*t ton of math is about crash down on you else if (c is SvgPath) // F*cking arcs { // SVG takes 2 points and 1 radius to draw arcs // Turing takes in 2 angles, 1 radius and 1 center point to draw it's arcs // See the problem? I see it.... var path = c as SvgPath; foreach (var p in path.PathData) { #region Arcs if (p is SvgArcSegment) { var arc = p as SvgArcSegment; //Assumption made about RadiusX = RadiusY, as the SVG program I used only supported circular arcs //So if you want to draw elliptical arcs, you are f****d. And I don't care anymore double cX, cY, sweepFrom, sweepTo; if ((arc.Sweep == SvgArcSweep.Positive) && (arc.Size == SvgArcSize.Large)) //Deal with the SVG arc flags { cX = nCenterX(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); cY = nCenterY(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); sweepTo = 180 * Math.Atan2(Math.Abs(cY - gH + arc.Start.Y), Math.Abs(arc.Start.X - cX)) / Math.PI; sweepFrom = 180 * Math.Atan2(Math.Abs(cY - gH + arc.End.Y), Math.Abs(arc.End.X - cX)) / Math.PI; sweepTo = adjustAngle(sweepTo, gH - arc.Start.Y - cY, arc.Start.X - cX); sweepFrom = adjustAngle(sweepFrom, gH - arc.End.Y - cY, arc.End.X - cX); } else if ((arc.Sweep == SvgArcSweep.Positive) && (arc.Size == SvgArcSize.Small)) { cX = pCenterX(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); cY = pCenterY(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); sweepTo = 180 * Math.Atan2(Math.Abs(cY - gH + arc.Start.Y), Math.Abs(arc.Start.X - cX)) / Math.PI; sweepFrom = 180 * Math.Atan2(Math.Abs(cY - gH + arc.End.Y), Math.Abs(arc.End.X - cX)) / Math.PI; sweepTo = adjustAngle(sweepTo, gH - arc.Start.Y - cY, arc.Start.X - cX); sweepFrom = adjustAngle(sweepFrom, gH - arc.End.Y - cY, arc.End.X - cX); } else if ((arc.Sweep == SvgArcSweep.Negative) && (arc.Size == SvgArcSize.Small)) { cX = nCenterX(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); cY = nCenterY(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); sweepFrom = 180 * Math.Atan2(Math.Abs(cY - gH + arc.Start.Y), Math.Abs(arc.Start.X - cX)) / Math.PI; sweepTo = 180 * Math.Atan2(Math.Abs(cY - gH + arc.End.Y), Math.Abs(arc.End.X - cX)) / Math.PI; sweepFrom = adjustAngle(sweepFrom, gH - arc.Start.Y - cY, arc.Start.X - cX); sweepTo = adjustAngle(sweepTo, gH - arc.End.Y - cY, arc.End.X - cX); } else { cX = pCenterX(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); cY = pCenterY(arc.Start.X, gH - arc.Start.Y, arc.End.X, gH - arc.End.Y, arc.RadiusX); sweepFrom = 180 * Math.Atan2(Math.Abs(cY - gH + arc.Start.Y), Math.Abs(arc.Start.X - cX)) / Math.PI; sweepTo = 180 * Math.Atan2(Math.Abs(cY - gH + arc.End.Y), Math.Abs(arc.End.X - cX)) / Math.PI; sweepFrom = adjustAngle(sweepFrom, gH - arc.Start.Y - cY, arc.Start.X - cX); sweepTo = adjustAngle(sweepTo, gH - arc.End.Y - cY, arc.End.X - cX); } //Deal with colour var sv = c.Stroke as SvgColourServer; if (cacheC1 != string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sv.Colour.R / 255f, sv.Colour.G / 255f, sv.Colour.B / 255f)) { cacheC1 = string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sv.Colour.R / 255f, sv.Colour.G / 255f, sv.Colour.B / 255f); sb.AppendLine(cacheC1); } if (sv.ToString() != "none") { sb.AppendLine(drawArc((int)cX, (int)cY, (int)arc.RadiusX, (int)arc.RadiusY, (int)sweepFrom, (int)sweepTo, getColor(sv.Colour.Name, false))); } } #endregion #region Cubic Beziers // Bezier curves // Full credits to: https://github.com/domoszlai/bezier2biarc // for the implementation. You are awesome! I don't have to read those research papers now :P else if (p is SvgCubicCurveSegment) { var b = p as SvgCubicCurveSegment; // Broken. TODO: Fix this please sb.AppendLine("% Bezier curves currenly broken. Sorry. Element id [" + c.ID + "]"); continue; //Bezier is broken CubicBezier curve = new CubicBezier( new Vector2(b.Start.X, b.Start.Y), new Vector2(b.FirstControlPoint.X, b.FirstControlPoint.Y), new Vector2(b.SecondControlPoint.X, b.SecondControlPoint.Y), new Vector2(b.End.X, b.End.Y)); /*curve = new CubicBezier( * new Vector2(100, 500), new Vector2(150, 100), new Vector2(500, 150), new Vector2(350, 350));*/ var biarcs = Algorithm.ApproxCubicBezier(curve, 10, 1); foreach (var biarc in biarcs) { int r1 = (int)Math.Ceiling((biarc.A1.startAngle * 180.0f / (float)Math.PI) > 360 ? -(biarc.A1.startAngle * 180.0f / (float)Math.PI) : 360 - (biarc.A1.startAngle * 180.0f / (float)Math.PI)); int r2 = (int)Math.Ceiling(biarc.A1.sweepAngle * 180.0f / (float)Math.PI); int r3 = (int)Math.Ceiling((biarc.A2.startAngle * 180.0f / (float)Math.PI) > 360 ? -(biarc.A2.startAngle * 180.0f / (float)Math.PI) : 360 - (biarc.A2.startAngle * 180.0f / (float)Math.PI)); int r4 = (int)Math.Ceiling(biarc.A2.sweepAngle * 180.0f / (float)Math.PI); sb.AppendLine(string.Format("Draw.Arc({0}, {1}, {2}, {3}, {4}, {5}, red)", (int)(biarc.A1.C.X), (int)(gH - biarc.A1.C.Y), (int)(biarc.A1.r), (int)(biarc.A1.r), (int)(r1), (int)(r1 + r2))); sb.AppendLine(string.Format("Draw.Arc({0}, {1}, {2}, {3}, {4}, {5}, red)", (int)(biarc.A2.C.X), (int)(gH - biarc.A2.C.Y), (int)(biarc.A2.r), (int)(biarc.A2.r), (int)(r3), (int)(r3 + r4))); } //End foreach } //End if #endregion } //End foreach } //End if #endregion #region Ellipse else if (c is SvgEllipse) { var e = c as SvgEllipse; var sColor = e.Stroke as SvgColourServer; var fColor = e.Fill as SvgColourServer; if ((sColor.ToString() != "none") && !isTuringColor(sColor.Colour.ToString())) { if (cacheC1 != string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sColor.Colour.R / 255f, sColor.Colour.G / 255f, sColor.Colour.B / 255f)) { cacheC1 = string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sColor.Colour.R / 255f, sColor.Colour.G / 255f, sColor.Colour.B / 255f); sb.AppendLine(cacheC1); } } if ((fColor.ToString() != "none") && !isTuringColor(fColor.Colour.ToString())) { if (cacheC2 != string.Format("c2 := RGB.AddColour({0}, {1}, {2})", fColor.Colour.R / 255f, fColor.Colour.G / 255f, fColor.Colour.B / 255f)) { cacheC2 = string.Format("c2 := RGB.AddColour({0}, {1}, {2})", fColor.Colour.R / 255f, fColor.Colour.G / 255f, fColor.Colour.B / 255f); sb.AppendLine(cacheC2); } } // Check and apply the stroke if ((e.StrokeWidth.Value > 0) && (sColor.ToString() != "none") && (!sColor.Colour.IsEmpty) && (sColor.Colour.A > 0)) { int width = (int)e.StrokeWidth.Value; sb.AppendLine(drawFillOval((int)e.CenterX, gH - (int)e.CenterY, (int)e.RadiusX + width, (int)e.RadiusY + width, getColor(sColor.Colour.ToString(), false))); } // Check if it is filled if ((fColor.ToString() != "none") && (!fColor.Colour.IsEmpty) && (fColor.Colour.A > 0)) { sb.AppendLine(drawFillOval((int)e.CenterX.Value, gH - (int)e.CenterY.Value, (int)e.RadiusX.Value, (int)e.RadiusY.Value, getColor(fColor.Colour.Name, true))); } else { sb.AppendLine(drawOval((int)e.CenterX.Value, gH - (int)e.CenterY.Value, (int)e.RadiusX.Value, (int)e.RadiusY.Value, getColor(sColor.Colour.Name, false))); } } #endregion #region Circles else if (c is SvgCircle) { var e = c as SvgCircle; var sColor = e.Stroke as SvgColourServer; var fColor = e.Fill as SvgColourServer; if ((sColor.ToString() != "none") && !isTuringColor(sColor.Colour.ToString())) { if (cacheC1 != string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sColor.Colour.R / 255f, sColor.Colour.G / 255f, sColor.Colour.B / 255f)) { cacheC1 = string.Format("c1 := RGB.AddColour({0}, {1}, {2})", sColor.Colour.R / 255f, sColor.Colour.G / 255f, sColor.Colour.B / 255f); sb.AppendLine(cacheC1); } } if ((fColor.ToString() != "none") && !isTuringColor(fColor.Colour.ToString())) { if (cacheC2 != string.Format("c2 := RGB.AddColour({0}, {1}, {2})", fColor.Colour.R / 255f, fColor.Colour.G / 255f, fColor.Colour.B / 255f)) { cacheC2 = string.Format("c2 := RGB.AddColour({0}, {1}, {2})", fColor.Colour.R / 255f, fColor.Colour.G / 255f, fColor.Colour.B / 255f); sb.AppendLine(cacheC2); } } // Check and apply the stroke if ((e.StrokeWidth.Value > 0) && (sColor.ToString() != "none") && (!sColor.Colour.IsEmpty) && (sColor.Colour.A > 0)) { int width = (int)e.StrokeWidth.Value; sb.AppendLine(drawFillOval((int)e.CenterX, gH - (int)e.CenterY, (int)e.Radius + width, (int)e.Radius + width, getColor(sColor.Colour.ToString(), false))); } //Check if it is filled if ((fColor.ToString() != "none") && (!fColor.Colour.IsEmpty) && (fColor.Colour.A > 0)) { sb.AppendLine(drawFillOval((int)e.CenterX.Value, gH - (int)e.CenterY.Value, (int)e.Radius.Value, (int)e.Radius.Value, getColor(fColor.Colour.Name, true))); } else { sb.AppendLine(drawOval((int)e.CenterX.Value, gH - (int)e.CenterY.Value, (int)e.Radius.Value, (int)e.Radius.Value, getColor(sColor.Colour.Name, false))); } } //End if #endregion } // End foreach //Return return(sb.ToString()); }