diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs index 49eb26d9..0f590f94 100644 --- a/SunnyUI/Charts/UILineChart.cs +++ b/SunnyUI/Charts/UILineChart.cs @@ -50,6 +50,7 @@ * 2023-07-14: V3.4.0 增加了坐标轴绘制时显示箭头,并在箭头处显示数量单位的功能 * 2023-10-04: V3.5.0 增加了Y轴数据由上向下绘制 * 2023-10-05: V3.5.0 增加了X轴和Y轴鼠标选择区域并返回选中范围 + * 2023-10-20: V3.5.1 增加了绘制线的DashStyle样式 ******************************************************************************/ using System; @@ -546,6 +547,8 @@ namespace Sunny.UI { using (Pen pen = new Pen(color, series.Width)) { + pen.DashStyle = series.DashStyle; + if (series.DashPattern.IsValid()) pen.DashPattern = series.DashPattern; g.SetHighQuality(); if (series is UISwitchLineSeries lineSeries) diff --git a/SunnyUI/Charts/UILineChartOption.cs b/SunnyUI/Charts/UILineChartOption.cs index f7ab0760..10d0db32 100644 --- a/SunnyUI/Charts/UILineChartOption.cs +++ b/SunnyUI/Charts/UILineChartOption.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Drawing2D; using System.Linq; namespace Sunny.UI @@ -496,6 +497,10 @@ namespace Sunny.UI public float Width { get; set; } = 2; public Color Color { get; set; } + public DashStyle DashStyle { get; set; } = DashStyle.Solid; + + public float[] DashPattern { get; set; } + public UILinePointSymbol Symbol { get; set; } = UILinePointSymbol.None; /// diff --git a/SunnyUI/Common/UGraphics.cs b/SunnyUI/Common/UGraphics.cs index 8991eec8..a40a52c6 100644 --- a/SunnyUI/Common/UGraphics.cs +++ b/SunnyUI/Common/UGraphics.cs @@ -268,11 +268,11 @@ namespace Sunny.UI /// 颜色 /// 文字中心点 /// 角度 - public static void DrawRotateString(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle) + public static void DrawRotateString(this Graphics g, string text, Font font, Color color, PointF centerPoint, float angle, int offsetX = 0, int offsetY = 0) { if (text.IsNullOrEmpty()) return; using Brush br = color.Brush(); - g.DrawRotateString(text, font, br, centerPoint, angle); + g.DrawRotateString(text, font, br, centerPoint, angle, offsetX, offsetY); } /// @@ -284,25 +284,25 @@ namespace Sunny.UI /// 笔刷 /// 文字中心点 /// 角度 - private static void DrawRotateString(this Graphics g, string text, Font font, Brush brush, PointF centerPoint, float angle) + private static void DrawRotateString(this Graphics g, string text, Font font, Brush brush, PointF centerPoint, float angle, int offsetX = 0, int offsetY = 0) { if (text.IsNullOrEmpty()) return; SizeF sf = TextRenderer.MeasureText(text, font); - float x1 = centerPoint.X - sf.Width / 2.0f; - float y1 = centerPoint.Y - sf.Height / 2.0f; + float x1 = centerPoint.X - sf.Width / 2.0f + offsetX; + float y1 = centerPoint.Y - sf.Height / 2.0f + offsetY; // 把画板的原点(默认是左上角)定位移到文字中心 - g.TranslateTransform(x1 + sf.Width / 2, y1 + sf.Height / 2); + g.TranslateTransform(x1 + sf.Width / 2.0f, y1 + sf.Height / 2.0f); // 旋转画板 g.RotateTransform(angle); // 回退画板x,y轴移动过的距离 - g.TranslateTransform(-(x1 + sf.Width / 2), -(y1 + sf.Height / 2)); + g.TranslateTransform(-(x1 + sf.Width / 2.0f), -(y1 + sf.Height / 2.0f)); g.DrawString(text, font, brush, x1, y1); //恢复 - g.TranslateTransform(x1 + sf.Width / 2, y1 + sf.Height / 2); + g.TranslateTransform(x1 + sf.Width / 2.0f, y1 + sf.Height / 2.0f); g.RotateTransform(-angle); - g.TranslateTransform(-(x1 + sf.Width / 2), -(y1 + sf.Height / 2)); + g.TranslateTransform(-(x1 + sf.Width / 2.0f), -(y1 + sf.Height / 2.0f)); } /// diff --git a/SunnyUI/Font/UFontImageHelper.cs b/SunnyUI/Font/UFontImageHelper.cs index 9a290653..23a7fae5 100644 --- a/SunnyUI/Font/UFontImageHelper.cs +++ b/SunnyUI/Font/UFontImageHelper.cs @@ -106,11 +106,35 @@ namespace Sunny.UI /// ƫ /// ƫ public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color, + RectangleF rect, int xOffset = 0, int yOffSet = 0, int angle = 0) + { + SizeF sf = graphics.GetFontImageSize(symbol, symbolSize); + + if (angle == 0) + { + graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(), + rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet); + } + else + { + graphics.DrawFontImage(symbol, symbolSize, color, angle, rect, xOffset, yOffSet); + } + } + + public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color, int angle, RectangleF rect, int xOffset = 0, int yOffSet = 0) { SizeF sf = graphics.GetFontImageSize(symbol, symbolSize); - graphics.DrawFontImage(symbol, symbolSize, color, rect.Left + ((rect.Width - sf.Width) / 2.0f).RoundEx(), - rect.Top + ((rect.Height - sf.Height) / 2.0f).RoundEx(), xOffset, yOffSet); + PointF center = rect.Center(); + Font font = GetFont(symbol, symbolSize); + + var symbolValue = GetSymbolValue(symbol); + string text = char.ConvertFromUtf32(symbolValue); + graphics.TextRenderingHint = TextRenderingHint.AntiAlias; + graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; + graphics.DrawRotateString(text, font, color, center, angle, xOffset, yOffSet); + graphics.TextRenderingHint = TextRenderingHint.SystemDefault; + graphics.InterpolationMode = InterpolationMode.Default; } /// @@ -127,12 +151,8 @@ namespace Sunny.UI public static void DrawFontImage(this Graphics graphics, int symbol, int symbolSize, Color color, float left, float top, int xOffset = 0, int yOffSet = 0) { - // Font font = GetFont(symbol, symbolSize); - if (font == null) - { - return; - } + if (font == null) return; var symbolValue = GetSymbolValue(symbol); string text = char.ConvertFromUtf32(symbolValue);