示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="style"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private static XPen ToXPen(Test2d.BaseStyle style, Func <double, double> scale)
        {
            var pen = new XPen(ToXColor(style.Stroke), XUnit.FromPresentation(style.Thickness));

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

            case Test2d.LineCap.Square:
                pen.LineCap = XLineCap.Square;
                break;

            case Test2d.LineCap.Round:
                pen.LineCap = XLineCap.Round;
                break;
            }
            if (style.Dashes != null)
            {
                // TODO: Convert to correct dash values.
                pen.DashPattern = style.Dashes;
            }
            pen.DashOffset = style.DashOffset;
            return(pen);
        }
示例#2
0
        private void DrawEllipseInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect)
        {
            var dxfEllipse = CreateEllipse(rect.X, rect.Y, rect.Width, rect.Height);

            if (isFilled)
            {
                var fill             = GetColor(style.Fill);
                var fillTransparency = GetTransparency(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;

                doc.AddEntity(hatch);
            }

            if (isStroked)
            {
                var stroke            = GetColor(style.Stroke);
                var strokeTansparency = GetTransparency(style.Stroke);
                var lineweight        = ThicknessToLineweight(style.Thickness);

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

                doc.AddEntity(dxfEllipse);
            }
        }
示例#3
0
        private void DrawRectangleInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect)
        {
            double x = rect.X;
            double y = rect.Y;
            double w = rect.Width;
            double h = rect.Height;

            var dxfLine1 = CreateLine(x, y, x + w, y);
            var dxfLine2 = CreateLine(x + w, y, x + w, y + h);
            var dxfLine3 = CreateLine(x + w, y + h, x, y + h);
            var dxfLine4 = CreateLine(x, y + h, x, y);

            if (isFilled)
            {
                var fill             = GetColor(style.Fill);
                var fillTransparency = GetTransparency(style.Fill);

                var bounds =
                    new List <HatchBoundaryPath>
                {
                    new HatchBoundaryPath(
                        new List <EntityObject>
                    {
                        (Line)dxfLine1.Clone(),
                        (Line)dxfLine2.Clone(),
                        (Line)dxfLine3.Clone(),
                        (Line)dxfLine4.Clone()
                    })
                };

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

                doc.AddEntity(hatch);
            }

            if (isStroked)
            {
                var stroke            = GetColor(style.Stroke);
                var strokeTansparency = GetTransparency(style.Stroke);
                var lineweight        = ThicknessToLineweight(style.Thickness);

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

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

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

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

                doc.AddEntity(dxfLine1);
                doc.AddEntity(dxfLine2);
                doc.AddEntity(dxfLine3);
                doc.AddEntity(dxfLine4);
            }
        }