|
@@ -5,6 +5,7 @@ using netDxf;
|
|
using netDxf.Entities;
|
|
using netDxf.Entities;
|
|
using netDxf.Objects;
|
|
using netDxf.Objects;
|
|
using netDxf.Tables;
|
|
using netDxf.Tables;
|
|
|
|
+using Svg;
|
|
using Point = System.Drawing.Point;
|
|
using Point = System.Drawing.Point;
|
|
|
|
|
|
namespace InABox.Dxf;
|
|
namespace InABox.Dxf;
|
|
@@ -127,7 +128,7 @@ public static class DxfUtils
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void DrawDxf(DxfData data, Graphics graphics)
|
|
|
|
|
|
+ public static void DrawDxf(DxfData data, IGraphics graphics, float width, float height)
|
|
{
|
|
{
|
|
// Calculate the scaling factor to fit the image within the bounds
|
|
// Calculate the scaling factor to fit the image within the bounds
|
|
float ratioX = (float)data.Settings.ImageSize.Width / data.Size.Width;
|
|
float ratioX = (float)data.Settings.ImageSize.Width / data.Size.Width;
|
|
@@ -137,8 +138,7 @@ public static class DxfUtils
|
|
|
|
|
|
var drawData = new DrawData() { Graphics = graphics, Data = data };
|
|
var drawData = new DrawData() { Graphics = graphics, Data = data };
|
|
|
|
|
|
- Brush _brush = new SolidBrush(Color.White);
|
|
|
|
- graphics.FillRectangle(_brush, 0, 0, graphics.VisibleClipBounds.Width, graphics.VisibleClipBounds.Height);
|
|
|
|
|
|
+ graphics.Clear(Color.White);
|
|
|
|
|
|
// drawData.Translate(graphics.VisibleClipBounds.Width / 2, graphics.VisibleClipBounds.Height / 2);
|
|
// drawData.Translate(graphics.VisibleClipBounds.Width / 2, graphics.VisibleClipBounds.Height / 2);
|
|
|
|
|
|
@@ -205,13 +205,28 @@ public static class DxfUtils
|
|
using (var _graphics = Graphics.FromImage(_result))
|
|
using (var _graphics = Graphics.FromImage(_result))
|
|
{
|
|
{
|
|
_graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
_graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
- DrawDxf(data, _graphics);
|
|
|
|
|
|
+ DrawDxf(data, new GdiGraphics(_graphics), _result.Width, _result.Height);
|
|
}
|
|
}
|
|
_result.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
|
_result.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
|
|
|
|
|
return _result;
|
|
return _result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static SvgDocument ProcessSvg(DxfData data)
|
|
|
|
+ {
|
|
|
|
+ var doc = new SvgDocument
|
|
|
|
+ {
|
|
|
|
+ ViewBox = new(data.Origin.X, data.Origin.Y, data.Size.Width, data.Size.Height)
|
|
|
|
+ };
|
|
|
|
+ var drawData = new DrawData() { Graphics = new SvgGraphics(doc), Data = data };
|
|
|
|
+ foreach(var el in data.Document.Entities.All)
|
|
|
|
+ {
|
|
|
|
+ var item = ConvertEl(el);
|
|
|
|
+ item?.Draw(drawData);
|
|
|
|
+ }
|
|
|
|
+ return doc;
|
|
|
|
+ }
|
|
|
|
+
|
|
public static Bitmap ProcessImage(Stream stream, DxfImportSettings? settings = null)
|
|
public static Bitmap ProcessImage(Stream stream, DxfImportSettings? settings = null)
|
|
{
|
|
{
|
|
return ProcessImage(LoadDxf(stream, settings));
|
|
return ProcessImage(LoadDxf(stream, settings));
|