public void DrawClosedCurve(AbstractPen pen, AbstractBrush brush, PointF[] points, float tension) { var e = Append(new Element(ElementNames.PATH)); e.Set("d", ToSVG(points, tension, true)); e.Apply(pen, brush); }
public void DrawPath(AbstractPen pen, AbstractBrush brush, AbstractPath path) { var e = Append(new Element(ElementNames.PATH)); e.Set("d", ToSVG(path)); e.Apply(pen, brush); }
// String is positioned relative to x,y according to TextFormat. // TextFormat also controls text alignment (left, center, right). // Handles embedded newlines. public static void DrawString(AbstractGraphics g, string text, Font font, AbstractBrush brush, float x, float y, TextFormat format = TextFormat.Center) { if (string.IsNullOrWhiteSpace(text)) { return; } var lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList(); var sizes = lines.Select(s => g.MeasureString(s, font)).ToList(); float fontUnitsToWorldUnits = font.Size / font.FontFamily.GetEmHeight(font.Style); float lineSpacing = font.FontFamily.GetLineSpacing(font.Style) * fontUnitsToWorldUnits; float ascent = font.FontFamily.GetCellAscent(font.Style) * fontUnitsToWorldUnits; //float descent = font.FontFamily.GetCellDescent(font.Style) * fontUnitsToWorldUnits; SizeF boundingSize = new SizeF(sizes.Max(s => s.Width), lineSpacing * sizes.Count()); // Offset from baseline to top-left. y += lineSpacing / 2; float widthFactor = 0; switch (format) { case TextFormat.MiddleLeft: case TextFormat.Center: case TextFormat.MiddleRight: y -= boundingSize.Height / 2; break; case TextFormat.BottomLeft: case TextFormat.BottomCenter: case TextFormat.BottomRight: y -= boundingSize.Height; break; } switch (format) { case TextFormat.TopCenter: case TextFormat.Center: case TextFormat.BottomCenter: widthFactor = -0.5f; break; case TextFormat.TopRight: case TextFormat.MiddleRight: case TextFormat.BottomRight: widthFactor = -1; break; } lines.ForEachZip(sizes, (line, sz) => { g.DrawString(line, font, brush, x + widthFactor * sz.Width + sz.Width / 2, y, Graphics.StringAlignment.Centered); y += lineSpacing; }); }
public void DrawRectangle(AbstractPen pen, AbstractBrush brush, float x, float y, float width, float height) { var e = Append(new Element(ElementNames.RECT)); e.Set("x", x); e.Set("y", y); e.Set("width", width); e.Set("height", height); e.Apply(pen, brush); }
public void DrawString(string s, Font font, AbstractBrush brush, float x, float y, StringAlignment format) { Apply(brush); if (format == StringAlignment.Baseline) { float fontUnitsToWorldUnits = font.Size / font.FontFamily.GetEmHeight(font.Style); float ascent = font.FontFamily.GetCellAscent(font.Style) * fontUnitsToWorldUnits; g.DrawString(s, font, this.brush, x, y - ascent); } else { g.DrawString(s, font, this.brush, x, y, Format(format)); } }
public void DrawString(string s, Font font, AbstractBrush brush, float x, float y, StringAlignment alignment) { var e = Append(new Element(ElementNames.TEXT)); e.content = s; e.Set("font-family", font.Name); e.Set("font-size", font.Size); if (font.Italic) { e.Set("font-style", "italic"); } if (font.Bold) { e.Set("font-weight", "bold"); } if (font.Underline) { e.Set("text-decoration", "underline"); } else if (font.Strikeout) { e.Set("text-decoration", "line-through"); } switch (alignment) { case StringAlignment.Centered: y += (font.Size * 0.85f) / 2; e.Set("text-anchor", "middle"); break; case StringAlignment.TopLeft: y += font.Size * 0.85f; break; case StringAlignment.TopCenter: y += font.Size * 0.85f; e.Set("text-anchor", "middle"); break; case StringAlignment.TopRight: y += font.Size * 0.85f; e.Set("text-anchor", "end"); break; case StringAlignment.CenterLeft: y += (font.Size * 0.85f) / 2; break; case StringAlignment.Baseline: break; default: throw new ApplicationException("Unhandled string alignment"); } e.Set("x", x); e.Set("y", y); e.Apply(brush); }
public void DrawEllipse(AbstractPen pen, AbstractBrush brush, float x, float y, float width, float height) { Element e; if (width == height) { e = Append(new Element(ElementNames.CIRCLE)); e.Set("r", width / 2); } else { e = Append(new Element(ElementNames.ELLIPSE)); e.Set("rx", width / 2); e.Set("ry", height / 2); } e.Set("cx", x + width / 2); e.Set("cy", y + height / 2); e.Apply(pen, brush); }
internal void Paint(AbstractGraphics graphics, Color dotColor, AbstractBrush labelBrush, AbstractFont labelFont) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } Point pt = Astrometrics.LocationToCoordinates(Location); using (graphics.Save()) { graphics.TranslateTransform(pt.X, pt.Y); graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); const float radius = 3; AbstractBrush brush = new AbstractBrush(dotColor); AbstractPen pen = new AbstractPen(dotColor); graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.DrawEllipse(pen, brush, -radius / 2, -radius / 2, radius, radius); RenderUtil.TextFormat format; if (LabelBiasX > 0) { format = LabelBiasY < 0 ? RenderUtil.TextFormat.BottomLeft : LabelBiasY > 0 ? RenderUtil.TextFormat.TopLeft : RenderUtil.TextFormat.MiddleLeft; } else if (LabelBiasX < 0) { format = LabelBiasY < 0 ? RenderUtil.TextFormat.BottomRight : LabelBiasY > 0 ? RenderUtil.TextFormat.TopRight : RenderUtil.TextFormat.MiddleRight; } else { format = LabelBiasY < 0 ? RenderUtil.TextFormat.BottomCenter : LabelBiasY > 0 ? RenderUtil.TextFormat.TopCenter : RenderUtil.TextFormat.Center; } float y = (LabelBiasY * radius / 2); float x = (LabelBiasX * radius / 2); RenderUtil.DrawString(graphics, Name, labelFont, labelBrush, x, y, format); } }
internal void Fill(AbstractGraphics graphics, RectangleF rect, AbstractBrush fillBrush) { if (graphics == null) { throw new ArgumentNullException("graphics"); } RectangleF bounds = TransformedBounds; if (bounds.IntersectsWith(rect)) { var path = Path; using (graphics.Save()) { XMatrix matrix = new XMatrix(); matrix.ScalePrepend(ScaleX, ScaleY); matrix.TranslatePrepend(-OriginX, -OriginY); graphics.MultiplyTransform(matrix); graphics.DrawPath(fillBrush, path); } } }
public void DrawPath(AbstractBrush brush, AbstractPath path) { DrawPath(null, brush, path); }
public void DrawEllipse(AbstractBrush brush, float x, float y, float width, float height) { Apply(brush); g.DrawEllipse(this.brush, x, y, width, height); }
public void DrawString(string s, Font font, AbstractBrush brush, float x, float y, StringAlignment format) { Apply(brush); g.DrawString(s, Convert(font), this.brush, x, y, Format(format)); }
public void DrawPath(AbstractBrush brush, AbstractPath path) { Apply(brush); g.FillPath(this.brush, new GraphicsPath(path.Points, path.Types, FillMode.Winding)); }
public void DrawClosedCurve(AbstractBrush brush, PointF[] points, float tension) { Apply(brush); g.FillClosedCurve(this.brush, points, FillMode.Winding, tension); }
private void Apply(AbstractBrush brush) { this.brush.Color = brush.Color; }
public void DrawClosedCurve(AbstractBrush brush, PointF[] points, float tension) { DrawClosedCurve(null, brush, points, tension); }
public void Apply(AbstractBrush brush) { Set("fill", brush?.Color ?? Color.Empty); }
public void DrawClosedCurve(AbstractBrush brush, PointF[] points, float tension) { Apply(brush); g.DrawClosedCurve(this.brush, points, XFillMode.Alternate, tension); }
public static void DrawLabel(AbstractGraphics g, string text, PointF center, AbstractFont font, AbstractBrush brush, LabelStyle labelStyle) { using (g.Save()) { if (labelStyle.Uppercase) { text = text.ToUpper(); } if (labelStyle.Wrap) { text = text.Replace(' ', '\n'); } g.TranslateTransform(center.X, center.Y); g.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); g.TranslateTransform(labelStyle.Translation.X, labelStyle.Translation.Y); g.RotateTransform(labelStyle.Rotation); g.ScaleTransform(labelStyle.Scale.Width, labelStyle.Scale.Height); if (labelStyle.Rotation != 0 && g.Graphics != null) { g.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; } DrawString(g, text, font, brush, 0, 0); } }
private void Apply(AbstractPen pen, AbstractBrush brush) { Apply(pen); Apply(brush); }
public void DrawRectangle(AbstractBrush brush, RectangleF rect) { Apply(brush); g.FillRectangle(this.brush, rect); }
public void DrawRectangle(AbstractBrush brush, RectangleF rect) { DrawRectangle(null, brush, rect.X, rect.Y, rect.Width, rect.Height); }
public void Apply(AbstractPen pen, AbstractBrush brush) { Apply(pen); Apply(brush); }
public void DrawEllipse(AbstractBrush brush, float x, float y, float width, float height) { DrawEllipse(null, brush, x, y, width, height); }
public void DrawRectangle(AbstractBrush brush, float x, float y, float width, float height) { Apply(brush); g.FillRectangle(this.brush, x, y, width, height); }
internal void DrawName(AbstractGraphics graphics, RectangleF rect, AbstractFont font, AbstractBrush textBrush, LabelStyle labelStyle) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } RectangleF bounds = TransformedBounds; if (bounds.IntersectsWith(rect)) { if (Name != null) { string str = Name; if (labelStyle.Uppercase) { str = str.ToUpperInvariant(); } PointF pos = NamePosition;// PointF( bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2 ); using (graphics.Save()) { graphics.TranslateTransform(pos.X, pos.Y); graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); graphics.RotateTransform(-labelStyle.Rotation); // Rotate it RenderUtil.DrawString(graphics, str, font, textBrush, 0, 0); } } } }
public void DrawEllipse(AbstractPen pen, AbstractBrush brush, float x, float y, float width, float height) { Apply(pen, brush); g.FillEllipse(this.brush, x, y, width, height); g.DrawEllipse(this.pen, x, y, width, height); }
public static void DrawGlyph(AbstractGraphics g, Glyph glyph, FontCache styleRes, AbstractBrush brush, PointF pt) { AbstractFont font; string s = glyph.Characters; if (g.SupportsWingdings && s.All(c => DING_MAP.ContainsKey(c))) { s = string.Join("", s.Select(c => DING_MAP[c])); font = styleRes.WingdingFont; } else { font = styleRes.GlyphFont; } g.DrawString(s, font, brush, pt.X, pt.Y, Maps.Graphics.StringAlignment.Centered); }
public void Apply(AbstractBrush brush) { Set("fill", brush == null ? Color.Empty : brush.Color); }