Exemple #1
0
        private static XPen ToXPen(Core2D.Style.BaseStyle style, Func <double, double> scale, double sourceDpi, double targetDpi)
        {
            var pen = new XPen(ToXColor(style.Stroke), scale(style.Thickness * targetDpi / sourceDpi));

            switch (style.LineCap)
            {
            case Core2D.Style.LineCap.Flat:
                pen.LineCap = XLineCap.Flat;
                break;

            case Core2D.Style.LineCap.Square:
                pen.LineCap = XLineCap.Square;
                break;

            case Core2D.Style.LineCap.Round:
                pen.LineCap = XLineCap.Round;
                break;
            }
            if (style.Dashes != null)
            {
                // TODO: Convert to correct dash values.
                pen.DashPattern = Core2D.Style.ShapeStyle.ConvertDashesToDoubleArray(style.Dashes);
            }
            pen.DashOffset = style.DashOffset;
            return(pen);
        }
Exemple #2
0
        private void DrawLineInternal(DxfDocument dxf, Layer layer, Core2D.Style.BaseStyle style, bool isStroked, double x1, double y1, double x2, double y2)
        {
            if (isStroked)
            {
                var stroke            = ToColor(style.Stroke);
                var strokeTansparency = ToTransparency(style.Stroke);
                var lineweight        = ToLineweight(style.Thickness);

                var dxfLine = CreateLine(x1, y1, x2, y2);

                dxfLine.Layer = layer;
                dxfLine.Color = stroke;
                dxfLine.Transparency.Value = strokeTansparency;
                dxfLine.Lineweight         = lineweight;

                dxf.AddEntity(dxfLine);
            }
        }
Exemple #3
0
        private void DrawEllipseInternal(DxfDocument dxf, Layer layer, bool isFilled, bool isStroked, Core2D.Style.BaseStyle style, ref Core2D.Math.Rect2 rect)
        {
            var dxfEllipse = CreateEllipse(rect.X, rect.Y, rect.Width, rect.Height);

            if (isFilled)
            {
                var fill             = ToColor(style.Fill);
                var fillTransparency = ToTransparency(style.Fill);

                // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360.
                var bounds =
                    new List <HatchBoundaryPath>
                {
                    new HatchBoundaryPath(
                        new List <EntityObject>
                    {
                        (Ellipse)dxfEllipse.Clone()
                    })
                };

                var hatch = new Hatch(HatchPattern.Solid, bounds, false);
                hatch.Layer = layer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                dxf.AddEntity(hatch);
            }

            if (isStroked)
            {
                var stroke            = ToColor(style.Stroke);
                var strokeTansparency = ToTransparency(style.Stroke);
                var lineweight        = ToLineweight(style.Thickness);

                dxfEllipse.Layer = layer;
                dxfEllipse.Color = stroke;
                dxfEllipse.Transparency.Value = strokeTansparency;
                dxfEllipse.Lineweight         = lineweight;

                dxf.AddEntity(dxfEllipse);
            }
        }
Exemple #4
0
        private void DrawRectangleInternal(DxfDocument dxf, Layer layer, bool isFilled, bool isStroked, Core2D.Style.BaseStyle style, ref Core2D.Math.Rect2 rect)
        {
            double x = rect.X;
            double y = rect.Y;
            double w = rect.Width;
            double h = rect.Height;

            if (isFilled)
            {
                var fill             = ToColor(style.Fill);
                var fillTransparency = ToTransparency(style.Fill);

                var bounds =
                    new List <HatchBoundaryPath>
                {
                    new HatchBoundaryPath(
                        new List <EntityObject>
                    {
                        CreateLine(x, y, x + w, y),
                        CreateLine(x + w, y, x + w, y + h),
                        CreateLine(x + w, y + h, x, y + h),
                        CreateLine(x, y + h, x, y)
                    })
                };

                var hatch = new Hatch(HatchPattern.Solid, bounds, false);
                hatch.Layer = layer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                dxf.AddEntity(hatch);
            }

            if (isStroked)
            {
                DrawLineInternal(dxf, layer, style, true, x, y, x + w, y);
                DrawLineInternal(dxf, layer, style, true, x + w, y, x + w, y + h);
                DrawLineInternal(dxf, layer, style, true, x + w, y + h, x, y + h);
                DrawLineInternal(dxf, layer, style, true, x, y + h, x, y);
            }
        }