private static void BuildPointRuleAssignment(StringBuilder sb, IMarkSymbol sym) { sb.Clear(); if (sym.Fill != null) { sb.Append(INDENT + INDENT).AppendLine($"fillColor = '#{ToHtmlColor(sym.Fill.ForegroundColor)}';"); } if (sym.Edge != null) { sb.Append(INDENT + INDENT).AppendLine($"edgeColor = '#{ToHtmlColor(sym.Edge.Color)}';"); sb.Append(INDENT + INDENT).AppendLine($"edgeThickness = '{sym.Edge.Thickness}';"); } }
private static void BuildPointRuleAssignment(StringBuilder sb, IMarkSymbol sym) { sb.Clear(); if (sym.Fill != null) { sb.Append(INDENT + INDENT).AppendLine($"fillColor = '#{ToHtmlColor(sym.Fill.ForegroundColor)}';"); } if (sym.Edge != null) { sb.Append(INDENT + INDENT).AppendLine($"edgeColor = '#{ToHtmlColor(sym.Edge.Color)}';"); sb.Append(INDENT + INDENT).AppendLine($"edgeThickness = '{sym.Edge.Thickness}';"); } switch (sym.Shape) { case ShapeType.Circle: sb.Append(INDENT + INDENT).AppendLine($"pointStyle = OLPointCircle"); break; case ShapeType.Cross: sb.Append(INDENT + INDENT).AppendLine($"pointStyle = OLPointCross"); break; case ShapeType.Square: sb.Append(INDENT + INDENT).AppendLine($"pointStyle = OLPointSquare"); break; case ShapeType.Star: sb.Append(INDENT + INDENT).AppendLine($"pointStyle = OLPointStar"); break; case ShapeType.Triangle: sb.Append(INDENT + INDENT).AppendLine($"pointStyle = OLPointTriangle"); break; case ShapeType.X: sb.Append(INDENT + INDENT).AppendLine($"pointStyle = OLPointX"); break; } }
private void Symbol_SelectedIndexChanged(object sender, System.EventArgs e) { if (m_inUpdate) return; bool isSymbol = false; ShapeType selectedShape = ShapeType.Circle; // see if need to change symbol type foreach (string s in Enum.GetNames(typeof(ShapeType))) if (string.Compare(s, (string)Symbol.SelectedValue, true) == 0) { selectedShape = (ShapeType)Enum.Parse(typeof(ShapeType), s); isSymbol = true; break; } if (m_item.Symbol.Type == PointSymbolType.Mark) m_lastMark = (IMarkSymbol)m_item.Symbol; else if (m_item.Symbol.Type == PointSymbolType.Font) m_lastFont = (IFontSymbol)m_item.Symbol; if (isSymbol) { //W2D symbol is not selected, so invalidate grpW2DStyle.Tag = null; bool update = m_item.Symbol != m_lastMark; if (m_lastMark == null) m_lastMark = _factory.CreateDefaultMarkSymbol(); m_lastMark.Shape = selectedShape; m_item.Symbol = m_lastMark; setUIForMarkSymbol(true); if (update) UpdateDisplay(); } else if (Symbol.SelectedIndex == 6) //Font { //W2D symbol is not selected, so invalidate grpW2DStyle.Tag = null; // user wants to change away FROM a valid 'Mark' symbol type // if ("Font..." == Symbol.SelectedText) bool update = m_item.Symbol != m_lastFont; if (m_lastFont == null) { m_lastFont = _factory.CreateDefaultFontSymbol(); m_lastFont.SizeContext = SizeContextType.DeviceUnits; m_lastFont.Rotation = "0"; m_lastFont.SizeX = "10"; m_lastFont.SizeY = "10"; m_lastFont.Unit = LengthUnitType.Points; } m_item.Symbol = m_lastFont; setUIForMarkSymbol(false); if (update) UpdateDisplay(); } else if (Symbol.SelectedIndex == 7) //Symbol { using (var picker = new SymbolPicker(m_editor.GetEditedResource().CurrentConnection)) { if (picker.ShowDialog() == DialogResult.OK) { bool update = m_item.Symbol != m_lastSymbol; if (m_lastSymbol == null) { m_lastSymbol = _factory.CreateDefaultW2DSymbol(picker.SymbolLibrary, picker.SymbolName); m_lastSymbol.SizeContext = SizeContextType.DeviceUnits; m_lastSymbol.Rotation = "0"; m_lastSymbol.SizeX = "10"; m_lastSymbol.SizeY = "10"; m_lastSymbol.Unit = LengthUnitType.Points; } m_item.Symbol = m_lastSymbol; //Store the W2D preview image grpW2DStyle.Tag = picker.SymbolImage; setUIForMarkSymbol(false); if (update) UpdateDisplay(); } } } else { //W2D symbol is not selected, so invalidate grpW2DStyle.Tag = null; MessageBox.Show(this, Strings.SymbolTypeNotSupported, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } UpdatePreviewResult(); if (Changed != null) Changed(this, new EventArgs()); }
public static void RenderPreviewPoint(Graphics g, Rectangle size, IMarkSymbol item) { if (item == null) { RenderPreviewFont(g, size, null); return; } //Adjust, since painting always excludes top/right and includes left/bottom Rectangle size_adj = new Rectangle(size.X, size.Y, size.Width - 1, size.Height - 1); Point[] points = null; int radius = Math.Min(size_adj.Width / 2, size_adj.Height / 2); int npoints = Math.Min(Math.Max(15, radius / 5), 100); Point center = new Point(size_adj.X + size_adj.Width / 2, size_adj.Y + size_adj.Height / 2); switch(item.Shape) { case ShapeType.Square: points = Rotate(CreateNGon(center, radius, 4), center, Math.PI / 4); break; case ShapeType.Star: Point[] outerStar = Rotate(CreateNGon(center, radius, 5), center, -Math.PI / 2); Point[] innerStar = Rotate(Rotate(CreateNGon(center, radius / 2, 5), center, -Math.PI / 2), center, Math.PI / 5); points = new Point[outerStar.Length + innerStar.Length]; for (int i = 0; i < points.Length; i++) points[i] = i % 2 == 0 ? outerStar[i >> 1] : innerStar[i >> 1]; //points = innerStar; break; case ShapeType.Triangle: points = Rotate(CreateNGon(center, radius, 3), center, Math.PI / 6); break; case ShapeType.Cross: case ShapeType.X: Point[] outerCross = Rotate(CreateNGon(center, radius, 4), center, -Math.PI / 2); Point[] innerCross = Rotate(Rotate(CreateNGon(center, radius / 2, 4), center, -Math.PI / 2), center, Math.PI / 4); points = new Point[13]; points[0] = new Point(innerCross[0].X, outerCross[0].Y); points[1] = innerCross[0]; points[2] = new Point(outerCross[1].X, innerCross[0].Y); points[3] = new Point(outerCross[1].X, innerCross[1].Y); points[4] = innerCross[1]; points[5] = new Point(innerCross[1].X, outerCross[2].Y); points[6] = new Point(innerCross[2].X, outerCross[2].Y); points[7] = innerCross[2]; points[8] = new Point(outerCross[3].X, innerCross[2].Y); points[9] = new Point(outerCross[3].X, innerCross[3].Y); points[10] = innerCross[3]; points[11] = new Point(innerCross[3].X, outerCross[0].Y); points[12] = new Point(innerCross[0].X, outerCross[0].Y); if (item.Shape == ShapeType.X) points = Rotate(points, center, Math.PI / 4); break; default: //Circle { points = CreateNGon(center, radius, Math.Min(Math.Max(15, radius / 5), 100)); break; } } if (item.Fill != null) { Brush b; Color? bgColor = null; Color? fgColor = null; try { bgColor = Utility.ParseHTMLColor(item.Fill.BackgroundColor); fgColor = Utility.ParseHTMLColor(item.Fill.ForegroundColor); } catch { } Image texture = null; foreach (ImageStylePicker.NamedImage img in FillImages) { if (img.Name == item.Fill.FillPattern) { //TODO: Figure out why we can't modify the palette... /*Image bmp = (Image)img.Image.Clone(); for(int i = 0; i < bmp.Palette.Entries.Length; i++) if (bmp.Palette.Entries[i].R == Color.Black.R && bmp.Palette.Entries[i].B == Color.Black.B && bmp.Palette.Entries[i].G == Color.Black.G) bmp.Palette.Entries[i] = item.Fill.ForegroundColor; else if (bmp.Palette.Entries[i].R == Color.White.R && bmp.Palette.Entries[i].B == Color.White.B && bmp.Palette.Entries[i].G == Color.White.G) bmp.Palette.Entries[i] = item.Fill.BackgroundColor; */ //Until the above is resolved, this is a VERY slow way to do it, even with app. 200 pixels //Unfortunately I don't want "unsafe" code here... Bitmap bmp = new Bitmap(img.Image); for (int y = 0; y < bmp.Height; y++) for (int x = 0; x < bmp.Width; x++) { Color c = bmp.GetPixel(x, y); if (c.R == Color.Black.R && c.B == Color.Black.B && c.G == Color.Black.G && fgColor.HasValue) bmp.SetPixel(x, y, fgColor.Value); else if (c.R == Color.White.R && c.B == Color.White.B && c.G == Color.White.G && bgColor.HasValue) bmp.SetPixel(x, y, bgColor.Value); } texture = bmp; break; } } if (texture == null && bgColor.HasValue) b = new SolidBrush(bgColor.Value); else b = new TextureBrush(texture); if (b != null) { g.FillPolygon(b, points); b.Dispose(); } } if (item.Edge != null) { Color? c = null; try { c = string.IsNullOrEmpty(item.Edge.Color) ? Color.White : Utility.ParseHTMLColor(item.Edge.Color); } catch { } if (c.HasValue) { using (Pen p = new Pen(c.Value, /* float.Parse(item.Edge.Thickness) */ 1)) //TODO: Calculate appropriate thickness g.DrawPolygon(p, points); //TODO: Implement line dash } } }
public static void RenderPreviewPoint(Graphics g, Rectangle size, IMarkSymbol item) { if (item == null) { RenderPreviewFont(g, size, null); return; } //Adjust, since painting always excludes top/right and includes left/bottom Rectangle size_adj = new Rectangle(size.X, size.Y, size.Width - 1, size.Height - 1); Point[] points = null; int radius = Math.Min(size_adj.Width / 2, size_adj.Height / 2); int npoints = Math.Min(Math.Max(15, radius / 5), 100); Point center = new Point(size_adj.X + size_adj.Width / 2, size_adj.Y + size_adj.Height / 2); switch (item.Shape) { case ShapeType.Square: points = Rotate(CreateNGon(center, radius, 4), center, Math.PI / 4); break; case ShapeType.Star: Point[] outerStar = Rotate(CreateNGon(center, radius, 5), center, -Math.PI / 2); Point[] innerStar = Rotate(Rotate(CreateNGon(center, radius / 2, 5), center, -Math.PI / 2), center, Math.PI / 5); points = new Point[outerStar.Length + innerStar.Length]; for (int i = 0; i < points.Length; i++) { points[i] = i % 2 == 0 ? outerStar[i >> 1] : innerStar[i >> 1]; } //points = innerStar; break; case ShapeType.Triangle: points = Rotate(CreateNGon(center, radius, 3), center, Math.PI / 6); break; case ShapeType.Cross: case ShapeType.X: Point[] outerCross = Rotate(CreateNGon(center, radius, 4), center, -Math.PI / 2); Point[] innerCross = Rotate(Rotate(CreateNGon(center, radius / 2, 4), center, -Math.PI / 2), center, Math.PI / 4); points = new Point[13]; points[0] = new Point(innerCross[0].X, outerCross[0].Y); points[1] = innerCross[0]; points[2] = new Point(outerCross[1].X, innerCross[0].Y); points[3] = new Point(outerCross[1].X, innerCross[1].Y); points[4] = innerCross[1]; points[5] = new Point(innerCross[1].X, outerCross[2].Y); points[6] = new Point(innerCross[2].X, outerCross[2].Y); points[7] = innerCross[2]; points[8] = new Point(outerCross[3].X, innerCross[2].Y); points[9] = new Point(outerCross[3].X, innerCross[3].Y); points[10] = innerCross[3]; points[11] = new Point(innerCross[3].X, outerCross[0].Y); points[12] = new Point(innerCross[0].X, outerCross[0].Y); if (item.Shape == ShapeType.X) { points = Rotate(points, center, Math.PI / 4); } break; default: //Circle { points = CreateNGon(center, radius, Math.Min(Math.Max(15, radius / 5), 100)); break; } } if (item.Fill != null) { Brush b; Color?bgColor = null; Color?fgColor = null; try { bgColor = Utility.ParseHTMLColor(item.Fill.BackgroundColor); fgColor = Utility.ParseHTMLColor(item.Fill.ForegroundColor); } catch { } Image texture = null; foreach (ImageStylePicker.NamedImage img in FillImages) { if (img.Name == item.Fill.FillPattern) { //TODO: Figure out why we can't modify the palette... /*Image bmp = (Image)img.Image.Clone(); * for(int i = 0; i < bmp.Palette.Entries.Length; i++) * if (bmp.Palette.Entries[i].R == Color.Black.R && bmp.Palette.Entries[i].B == Color.Black.B && bmp.Palette.Entries[i].G == Color.Black.G) * bmp.Palette.Entries[i] = item.Fill.ForegroundColor; * else if (bmp.Palette.Entries[i].R == Color.White.R && bmp.Palette.Entries[i].B == Color.White.B && bmp.Palette.Entries[i].G == Color.White.G) * bmp.Palette.Entries[i] = item.Fill.BackgroundColor; */ //Until the above is resolved, this is a VERY slow way to do it, even with app. 200 pixels //Unfortunately I don't want "unsafe" code here... Bitmap bmp = new Bitmap(img.Image); for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { Color c = bmp.GetPixel(x, y); if (c.R == Color.Black.R && c.B == Color.Black.B && c.G == Color.Black.G && fgColor.HasValue) { bmp.SetPixel(x, y, fgColor.Value); } else if (c.R == Color.White.R && c.B == Color.White.B && c.G == Color.White.G && bgColor.HasValue) { bmp.SetPixel(x, y, bgColor.Value); } } } texture = bmp; break; } } if (texture == null && bgColor.HasValue) { b = new SolidBrush(bgColor.Value); } else { b = new TextureBrush(texture); } if (b != null) { g.FillPolygon(b, points); b.Dispose(); } } if (item.Edge != null) { Color?c = null; try { c = string.IsNullOrEmpty(item.Edge.Color) ? Color.White : Utility.ParseHTMLColor(item.Edge.Color); } catch { } if (c.HasValue) { using (Pen p = new Pen(c.Value, /* float.Parse(item.Edge.Thickness) */ 1)) //TODO: Calculate appropriate thickness g.DrawPolygon(p, points); //TODO: Implement line dash } } }