Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="layer"></param>
 /// <param name="db"></param>
 /// <param name="r"></param>
 public void Draw(object gfx, Core2D.Layer layer, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
 {
     foreach (var shape in layer.Shapes)
     {
         if (shape.State.Flags.HasFlag(_state.DrawShapeState.Flags))
         {
             shape.Draw(gfx, this, 0, 0, db, r);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="line"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XLine line, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!line.IsStroked)
            {
                return;
            }

            var _gfx = gfx as XGraphics;

            XSolidBrush fillLine   = ToXSolidBrush(line.Style.Fill);
            XPen        strokeLine = ToXPen(line.Style, _scaleToPage);

            XSolidBrush fillStartArrow   = ToXSolidBrush(line.Style.StartArrowStyle.Fill);
            XPen        strokeStartArrow = ToXPen(line.Style.StartArrowStyle, _scaleToPage);

            XSolidBrush fillEndArrow   = ToXSolidBrush(line.Style.EndArrowStyle.Fill);
            XPen        strokeEndArrow = ToXPen(line.Style.EndArrowStyle, _scaleToPage);

            double _x1 = line.Start.X + dx;
            double _y1 = line.Start.Y + dy;
            double _x2 = line.End.X + dx;
            double _y2 = line.End.Y + dy;

            Core2D.XLine.SetMaxLength(line, ref _x1, ref _y1, ref _x2, ref _y2);

            double x1 = _scaleToPage(_x1);
            double y1 = _scaleToPage(_y1);
            double x2 = _scaleToPage(_x2);
            double y2 = _scaleToPage(_y2);

            var    sas = line.Style.StartArrowStyle;
            var    eas = line.Style.EndArrowStyle;
            double a1  = Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI;
            double a2  = Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI;

            var t1 = new XMatrix();
            var c1 = new XPoint(x1, y1);

            t1.RotateAtPrepend(a1, c1);

            var t2 = new XMatrix();
            var c2 = new XPoint(x2, y2);

            t2.RotateAtPrepend(a2, c2);

            XPoint pt1;
            XPoint pt2;

            double radiusX1 = sas.RadiusX;
            double radiusY1 = sas.RadiusY;
            double sizeX1   = 2.0 * radiusX1;
            double sizeY1   = 2.0 * radiusY1;

            switch (sas.ArrowType)
            {
            default:
            case Core2D.ArrowType.None:
            {
                pt1 = new XPoint(x1, y1);
            }
            break;

            case Core2D.ArrowType.Rectangle:
            {
                pt1 = t1.Transform(new XPoint(x1 - sizeX1, y1));
                var rect = new XRect(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                _gfx.Save();
                _gfx.RotateAtTransform(a1, c1);
                DrawRectangleInternal(_gfx, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Ellipse:
            {
                pt1 = t1.Transform(new XPoint(x1 - sizeX1, y1));
                _gfx.Save();
                _gfx.RotateAtTransform(a1, c1);
                var rect = new XRect(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                DrawEllipseInternal(_gfx, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Arrow:
            {
                pt1 = t1.Transform(new XPoint(x1, y1));
                var p11 = t1.Transform(new XPoint(x1 - sizeX1, y1 + sizeY1));
                var p21 = t1.Transform(new XPoint(x1, y1));
                var p12 = t1.Transform(new XPoint(x1 - sizeX1, y1 - sizeY1));
                var p22 = t1.Transform(new XPoint(x1, y1));
                DrawLineInternal(_gfx, strokeStartArrow, sas.IsStroked, ref p11, ref p21);
                DrawLineInternal(_gfx, strokeStartArrow, sas.IsStroked, ref p12, ref p22);
            }
            break;
            }

            double radiusX2 = eas.RadiusX;
            double radiusY2 = eas.RadiusY;
            double sizeX2   = 2.0 * radiusX2;
            double sizeY2   = 2.0 * radiusY2;

            switch (eas.ArrowType)
            {
            default:
            case Core2D.ArrowType.None:
            {
                pt2 = new XPoint(x2, y2);
            }
            break;

            case Core2D.ArrowType.Rectangle:
            {
                pt2 = t2.Transform(new XPoint(x2 - sizeX2, y2));
                var rect = new XRect(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                _gfx.Save();
                _gfx.RotateAtTransform(a2, c2);
                DrawRectangleInternal(_gfx, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Ellipse:
            {
                pt2 = t2.Transform(new XPoint(x2 - sizeX2, y2));
                _gfx.Save();
                _gfx.RotateAtTransform(a2, c2);
                var rect = new XRect(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                DrawEllipseInternal(_gfx, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Arrow:
            {
                pt2 = t2.Transform(new XPoint(x2, y2));
                var p11 = t2.Transform(new XPoint(x2 - sizeX2, y2 + sizeY2));
                var p21 = t2.Transform(new XPoint(x2, y2));
                var p12 = t2.Transform(new XPoint(x2 - sizeX2, y2 - sizeY2));
                var p22 = t2.Transform(new XPoint(x2, y2));
                DrawLineInternal(_gfx, strokeEndArrow, eas.IsStroked, ref p11, ref p21);
                DrawLineInternal(_gfx, strokeEndArrow, eas.IsStroked, ref p12, ref p22);
            }
            break;
            }

            _gfx.DrawLine(strokeLine, pt1, pt2);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="path"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XPath path, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var gp = path.Geometry.ToXGraphicsPath(dx, dy, _scaleToPage);

            if (path.IsFilled && path.IsStroked)
            {
                _gfx.DrawPath(
                    ToXPen(path.Style, _scaleToPage),
                    ToXSolidBrush(path.Style.Fill),
                    gp);
            }
            else if (path.IsFilled && !path.IsStroked)
            {
                _gfx.DrawPath(
                    ToXSolidBrush(path.Style.Fill),
                    gp);
            }
            else if (!path.IsFilled && path.IsStroked)
            {
                _gfx.DrawPath(
                    ToXPen(path.Style, _scaleToPage),
                    gp);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="container"></param>
 /// <param name="db"></param>
 /// <param name="r"></param>
 public void Draw(object gfx, Core2D.Container container, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
 {
     foreach (var layer in container.Layers)
     {
         if (layer.IsVisible)
         {
             Draw(gfx, layer, db, r);
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="qbezier"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XQBezier qbezier, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            double x1 = qbezier.Point1.X;
            double y1 = qbezier.Point1.Y;
            double x2 = qbezier.Point1.X + (2.0 * (qbezier.Point2.X - qbezier.Point1.X)) / 3.0;
            double y2 = qbezier.Point1.Y + (2.0 * (qbezier.Point2.Y - qbezier.Point1.Y)) / 3.0;
            double x3 = x2 + (qbezier.Point3.X - qbezier.Point1.X) / 3.0;
            double y3 = y2 + (qbezier.Point3.Y - qbezier.Point1.Y) / 3.0;
            double x4 = qbezier.Point3.X;
            double y4 = qbezier.Point3.Y;

            if (qbezier.IsFilled)
            {
                var path = new XGraphicsPath();
                path.AddBezier(
                    _scaleToPage(x1 + dx),
                    _scaleToPage(y1 + dy),
                    _scaleToPage(x2 + dx),
                    _scaleToPage(y2 + dy),
                    _scaleToPage(x3 + dx),
                    _scaleToPage(y3 + dy),
                    _scaleToPage(x4 + dx),
                    _scaleToPage(y4 + dy));

                if (qbezier.IsStroked)
                {
                    _gfx.DrawPath(
                        ToXPen(qbezier.Style, _scaleToPage),
                        ToXSolidBrush(qbezier.Style.Fill),
                        path);
                }
                else
                {
                    _gfx.DrawPath(
                        ToXSolidBrush(qbezier.Style.Fill),
                        path);
                }
            }
            else
            {
                if (qbezier.IsStroked)
                {
                    _gfx.DrawBezier(
                        ToXPen(qbezier.Style, _scaleToPage),
                        _scaleToPage(x1 + dx),
                        _scaleToPage(y1 + dy),
                        _scaleToPage(x2 + dx),
                        _scaleToPage(y2 + dy),
                        _scaleToPage(x3 + dx),
                        _scaleToPage(y3 + dy),
                        _scaleToPage(x4 + dx),
                        _scaleToPage(y4 + dy));
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="path"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XPath path, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!path.IsStroked && !path.IsFilled)
            {
                return;
            }

            var _doc  = doc as DxfDocument;
            var style = path.Style;

            ICollection <HatchBoundaryPath> bounds;
            ICollection <EntityObject>      entities;

            CreateHatchBoundsAndEntitiess(path.Geometry, dx, dy, out bounds, out entities);
            if (entities == null || bounds == null)
            {
                return;
            }

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

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

                _doc.AddEntity(hatch);
            }

            if (path.IsStroked)
            {
                // TODO: Add support for Closed paths.

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

                foreach (var entity in entities)
                {
                    entity.Layer = _currentLayer;
                    entity.Color = stroke;
                    entity.Transparency.Value = strokeTansparency;
                    entity.Lineweight.Value   = lineweight;
                    _doc.AddEntity(entity);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XArc arc, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _doc  = doc as DxfDocument;
            var style = arc.Style;

            var dxfEllipse = CreateEllipticalArc(arc, dx, dy);

            if (arc.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 = _currentLayer;
                hatch.Color = fill;
                hatch.Transparency.Value = fillTransparency;

                _doc.AddEntity(hatch);
            }

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

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

                _doc.AddEntity(dxfEllipse);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XArc arc, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var a = Core2D.GdiArc.FromXArc(arc, dx, dy);

            if (arc.IsFilled)
            {
                var path = new XGraphicsPath();
                // NOTE: Not implemented in PdfSharp Core version.
                path.AddArc(
                    _scaleToPage(a.X),
                    _scaleToPage(a.Y),
                    _scaleToPage(a.Width),
                    _scaleToPage(a.Height),
                    a.StartAngle,
                    a.SweepAngle);

                if (arc.IsStroked)
                {
                    _gfx.DrawPath(
                        ToXPen(arc.Style, _scaleToPage),
                        ToXSolidBrush(arc.Style.Fill),
                        path);
                }
                else
                {
                    _gfx.DrawPath(
                        ToXSolidBrush(arc.Style.Fill),
                        path);
                }
            }
            else
            {
                if (arc.IsStroked)
                {
                    _gfx.DrawArc(
                        ToXPen(arc.Style, _scaleToPage),
                        _scaleToPage(a.X),
                        _scaleToPage(a.Y),
                        _scaleToPage(a.Width),
                        _scaleToPage(a.Height),
                        a.StartAngle,
                        a.SweepAngle);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="rectangle"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XRectangle rectangle, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!rectangle.IsStroked && !rectangle.IsFilled && !rectangle.IsGrid)
            {
                return;
            }

            var _doc  = doc as DxfDocument;
            var style = rectangle.Style;
            var rect  = Core2D.Rect2.Create(rectangle.TopLeft, rectangle.BottomRight, dx, dy);

            DrawRectangleInternal(_doc, _currentLayer, rectangle.IsFilled, rectangle.IsStroked, style, ref rect);

            if (rectangle.IsGrid)
            {
                DrawGridInternal(
                    _doc,
                    _currentLayer,
                    style,
                    rectangle.OffsetX, rectangle.OffsetY,
                    rectangle.CellWidth, rectangle.CellHeight,
                    ref rect);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="ellipse"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XEllipse ellipse, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!ellipse.IsStroked && !ellipse.IsFilled)
            {
                return;
            }

            var _doc  = doc as DxfDocument;
            var style = ellipse.Style;
            var rect  = Core2D.Rect2.Create(ellipse.TopLeft, ellipse.BottomRight, dx, dy);

            DrawEllipseInternal(_doc, _currentLayer, ellipse.IsFilled, ellipse.IsStroked, style, ref rect);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="line"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XLine line, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!line.IsStroked)
            {
                return;
            }

            var _doc = doc as DxfDocument;

            var style             = line.Style;
            var stroke            = GetColor(style.Stroke);
            var strokeTansparency = GetTransparency(style.Stroke);
            var lineweight        = ThicknessToLineweight(style.Thickness);

            double _x1 = line.Start.X + dx;
            double _y1 = line.Start.Y + dy;
            double _x2 = line.End.X + dx;
            double _y2 = line.End.Y + dy;

            Core2D.XLine.SetMaxLength(line, ref _x1, ref _y1, ref _x2, ref _y2);

            var dxfLine = CreateLine(_x1, _y1, _x2, _y2);

            // TODO: Draw line start arrow.

            // TODO: Draw line end arrow.

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

            _doc.AddEntity(dxfLine);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="layer"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.Layer layer, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _doc = doc as DxfDocument;

            foreach (var shape in layer.Shapes)
            {
                if (shape.State.Flags.HasFlag(_state.DrawShapeState.Flags))
                {
                    shape.Draw(_doc, this, 0, 0, db, r);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="container"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.Container container, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _doc = doc as DxfDocument;

            foreach (var layer in container.Layers)
            {
                var dxfLayer = new Layer(layer.Name)
                {
                    IsVisible = layer.IsVisible
                };

                _doc.Layers.Add(dxfLayer);

                _currentLayer = dxfLayer;

                Draw(doc, layer, db, r);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="rectangle"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XRectangle rectangle, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var rect = Core2D.Rect2.Create(
                rectangle.TopLeft,
                rectangle.BottomRight,
                dx, dy);

            if (rectangle.IsStroked && rectangle.IsFilled)
            {
                _gfx.DrawRectangle(
                    ToXPen(rectangle.Style, _scaleToPage),
                    ToXSolidBrush(rectangle.Style.Fill),
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }
            else if (rectangle.IsStroked && !rectangle.IsFilled)
            {
                _gfx.DrawRectangle(
                    ToXPen(rectangle.Style, _scaleToPage),
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }
            else if (!rectangle.IsStroked && rectangle.IsFilled)
            {
                _gfx.DrawRectangle(
                    ToXSolidBrush(rectangle.Style.Fill),
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }

            if (rectangle.IsGrid && rectangle.IsStroked)
            {
                DrawGridInternal(
                    _gfx,
                    ToXPen(rectangle.Style, _scaleToPage),
                    ref rect,
                    rectangle.OffsetX, rectangle.OffsetY,
                    rectangle.CellWidth, rectangle.CellHeight,
                    true);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="qbezier"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XQBezier qbezier, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!qbezier.IsStroked && !qbezier.IsFilled)
            {
                return;
            }

            var _doc  = doc as DxfDocument;
            var style = qbezier.Style;

            var dxfSpline = CreateQuadraticSpline(
                qbezier.Point1.X + dx,
                qbezier.Point1.Y + dy,
                qbezier.Point2.X + dx,
                qbezier.Point2.Y + dy,
                qbezier.Point3.X + dx,
                qbezier.Point3.Y + dy);

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

                var bounds =
                    new List <HatchBoundaryPath>
                {
                    new HatchBoundaryPath(
                        new List <EntityObject>
                    {
                        (Spline)dxfSpline.Clone()
                    })
                };

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

                _doc.AddEntity(hatch);
            }

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

                dxfSpline.Layer = _currentLayer;
                dxfSpline.Color = stroke;
                dxfSpline.Transparency.Value = strokeTansparency;
                dxfSpline.Lineweight.Value   = lineweight;

                _doc.AddEntity(dxfSpline);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="ellipse"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XEllipse ellipse, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var rect = Core2D.Rect2.Create(
                ellipse.TopLeft,
                ellipse.BottomRight,
                dx, dy);

            if (ellipse.IsStroked && ellipse.IsFilled)
            {
                _gfx.DrawEllipse(
                    ToXPen(ellipse.Style, _scaleToPage),
                    ToXSolidBrush(ellipse.Style.Fill),
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }
            else if (ellipse.IsStroked && !ellipse.IsFilled)
            {
                _gfx.DrawEllipse(
                    ToXPen(ellipse.Style, _scaleToPage),
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }
            else if (!ellipse.IsStroked && ellipse.IsFilled)
            {
                _gfx.DrawEllipse(
                    ToXSolidBrush(ellipse.Style.Fill),
                    _scaleToPage(rect.X),
                    _scaleToPage(rect.Y),
                    _scaleToPage(rect.Width),
                    _scaleToPage(rect.Height));
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XText text, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _doc = doc as DxfDocument;

            var tbind = text.BindToTextProperty(db, r);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            var style             = text.Style;
            var stroke            = GetColor(style.Stroke);
            var strokeTansparency = GetTransparency(style.Stroke);

            var    attachmentPoint = default(MTextAttachmentPoint);
            double x, y;
            var    rect = Core2D.Rect2.Create(text.TopLeft, text.BottomRight, dx, dy);

            switch (text.Style.TextStyle.TextHAlignment)
            {
            default:
            case Core2D.TextHAlignment.Left:
                x = rect.X;
                break;

            case Core2D.TextHAlignment.Center:
                x = rect.X + rect.Width / 2.0;
                break;

            case Core2D.TextHAlignment.Right:
                x = rect.X + rect.Width;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            default:
            case Core2D.TextVAlignment.Top:
                y = rect.Y;
                break;

            case Core2D.TextVAlignment.Center:
                y = rect.Y + rect.Height / 2.0;
                break;

            case Core2D.TextVAlignment.Bottom:
                y = rect.Y + rect.Height;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            default:
            case Core2D.TextVAlignment.Top:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case Core2D.TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.TopLeft;
                    break;

                case Core2D.TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.TopCenter;
                    break;

                case Core2D.TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.TopRight;
                    break;
                }
                break;

            case Core2D.TextVAlignment.Center:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case Core2D.TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.MiddleLeft;
                    break;

                case Core2D.TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.MiddleCenter;
                    break;

                case Core2D.TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.MiddleRight;
                    break;
                }
                break;

            case Core2D.TextVAlignment.Bottom:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case Core2D.TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.BottomLeft;
                    break;

                case Core2D.TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.BottomCenter;
                    break;

                case Core2D.TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.BottomRight;
                    break;
                }
                break;
            }

            var ts       = new TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile);
            var dxfMText = new MText(
                new Vector3(ToDxfX(x), ToDxfY(y), 0),
                text.Style.TextStyle.FontSize * 72.0 / 96.0,
                rect.Width,
                ts);

            dxfMText.AttachmentPoint = attachmentPoint;

            var fs      = text.Style.TextStyle.FontStyle;
            var options = new MTextFormattingOptions(dxfMText.Style);

            options.Bold          = fs.Flags.HasFlag(Core2D.FontStyleFlags.Bold);
            options.Italic        = fs.Flags.HasFlag(Core2D.FontStyleFlags.Italic);
            options.Underline     = fs.Flags.HasFlag(Core2D.FontStyleFlags.Underline);
            options.StrikeThrough = fs.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout);

            options.Aligment = MTextFormattingOptions.TextAligment.Default;
            options.Color    = null;
            dxfMText.Write(tbind, options);

            dxfMText.Layer = _currentLayer;
            dxfMText.Transparency.Value = strokeTansparency;
            dxfMText.Color = stroke;

            _doc.AddEntity(dxfMText);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="bezier"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XBezier bezier, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            if (bezier.IsFilled)
            {
                var path = new XGraphicsPath();
                path.AddBezier(
                    _scaleToPage(bezier.Point1.X + dx),
                    _scaleToPage(bezier.Point1.Y + dy),
                    _scaleToPage(bezier.Point2.X + dx),
                    _scaleToPage(bezier.Point2.Y + dy),
                    _scaleToPage(bezier.Point3.X + dx),
                    _scaleToPage(bezier.Point3.Y + dy),
                    _scaleToPage(bezier.Point4.X + dx),
                    _scaleToPage(bezier.Point4.Y + dy));

                if (bezier.IsStroked)
                {
                    _gfx.DrawPath(
                        ToXPen(bezier.Style, _scaleToPage),
                        ToXSolidBrush(bezier.Style.Fill),
                        path);
                }
                else
                {
                    _gfx.DrawPath(
                        ToXSolidBrush(bezier.Style.Fill),
                        path);
                }
            }
            else
            {
                if (bezier.IsStroked)
                {
                    _gfx.DrawBezier(
                        ToXPen(bezier.Style, _scaleToPage),
                        _scaleToPage(bezier.Point1.X + dx),
                        _scaleToPage(bezier.Point1.Y + dy),
                        _scaleToPage(bezier.Point2.X + dx),
                        _scaleToPage(bezier.Point2.Y + dy),
                        _scaleToPage(bezier.Point3.X + dx),
                        _scaleToPage(bezier.Point3.Y + dy),
                        _scaleToPage(bezier.Point4.X + dx),
                        _scaleToPage(bezier.Point4.Y + dy));
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="image"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XImage image, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var rect = Core2D.Rect2.Create(
                image.TopLeft,
                image.BottomRight,
                dx, dy);

            var srect = new XRect(
                _scaleToPage(rect.X),
                _scaleToPage(rect.Y),
                _scaleToPage(rect.Width),
                _scaleToPage(rect.Height));

            if (image.IsStroked && image.IsFilled)
            {
                _gfx.DrawRectangle(
                    ToXPen(image.Style, _scaleToPage),
                    ToXSolidBrush(image.Style.Fill),
                    srect);
            }
            else if (image.IsStroked && !image.IsFilled)
            {
                _gfx.DrawRectangle(
                    ToXPen(image.Style, _scaleToPage),
                    srect);
            }
            else if (!image.IsStroked && image.IsFilled)
            {
                _gfx.DrawRectangle(
                    ToXSolidBrush(image.Style.Fill),
                    srect);
            }

            if (_enableImageCache &&
                _biCache.ContainsKey(image.Path))
            {
                _gfx.DrawImage(_biCache[image.Path], srect);
            }
            else
            {
                if (_state.ImageCache == null || string.IsNullOrEmpty(image.Path))
                {
                    return;
                }

                var bytes = _state.ImageCache.GetImage(image.Path);
                if (bytes != null)
                {
                    var ms = new System.IO.MemoryStream(bytes);
#if WPF
                    var bs = new BitmapImage();
                    bs.BeginInit();
                    bs.StreamSource = ms;
                    bs.EndInit();
                    bs.Freeze();
                    var bi = XImage.FromBitmapSource(bs);
#else
                    var bi = XImage.FromStream(ms);
#endif
                    if (_enableImageCache)
                    {
                        _biCache[image.Path] = bi;
                    }

                    _gfx.DrawImage(bi, srect);

                    if (!_enableImageCache)
                    {
                        bi.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XText text, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var tbind = text.BindToTextProperty(db, r);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            var options = new XPdfFontOptions(PdfFontEncoding.Unicode);

            var fontStyle = XFontStyle.Regular;

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Bold))
            {
                fontStyle |= XFontStyle.Bold;
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Italic))
            {
                fontStyle |= XFontStyle.Italic;
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline))
            {
                fontStyle |= XFontStyle.Underline;
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout))
            {
                fontStyle |= XFontStyle.Strikeout;
            }

            var font = new XFont(
                text.Style.TextStyle.FontName,
                _scaleToPage(text.Style.TextStyle.FontSize),
                fontStyle,
                options);

            var rect = Core2D.Rect2.Create(
                text.TopLeft,
                text.BottomRight,
                dx, dy);

            var srect = new XRect(
                _scaleToPage(rect.X),
                _scaleToPage(rect.Y),
                _scaleToPage(rect.Width),
                _scaleToPage(rect.Height));

            var format = new XStringFormat();

            switch (text.Style.TextStyle.TextHAlignment)
            {
            case Core2D.TextHAlignment.Left:
                format.Alignment = XStringAlignment.Near;
                break;

            case Core2D.TextHAlignment.Center:
                format.Alignment = XStringAlignment.Center;
                break;

            case Core2D.TextHAlignment.Right:
                format.Alignment = XStringAlignment.Far;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            case Core2D.TextVAlignment.Top:
                format.LineAlignment = XLineAlignment.Near;
                break;

            case Core2D.TextVAlignment.Center:
                format.LineAlignment = XLineAlignment.Center;
                break;

            case Core2D.TextVAlignment.Bottom:
                format.LineAlignment = XLineAlignment.Far;
                break;
            }

            _gfx.DrawString(
                tbind,
                font,
                ToXSolidBrush(text.Style.Stroke),
                srect,
                format);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="image"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XImage image, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _doc = doc as DxfDocument;

            var bytes = _state.ImageCache.GetImage(image.Path);

            if (bytes != null)
            {
                var rect = Core2D.Rect2.Create(image.TopLeft, image.BottomRight, dx, dy);

                if (_enableImageCache &&
                    _biCache.ContainsKey(image.Path))
                {
                    var dxfImageDefinition = _biCache[image.Path];
                    var dxfImage           = new Image(
                        dxfImageDefinition,
                        new Vector3(ToDxfX(rect.X), ToDxfY(rect.Y + rect.Height), 0),
                        rect.Width,
                        rect.Height);
                    _doc.AddEntity(dxfImage);
                }
                else
                {
                    if (_state.ImageCache == null || string.IsNullOrEmpty(image.Path))
                    {
                        return;
                    }

                    var path = System.IO.Path.Combine(_outputPath, System.IO.Path.GetFileName(image.Path));
                    System.IO.File.WriteAllBytes(path, bytes);
                    var dxfImageDefinition = new ImageDef(path);

                    if (_enableImageCache)
                    {
                        _biCache[image.Path] = dxfImageDefinition;
                    }

                    var dxfImage = new Image(
                        dxfImageDefinition,
                        new Vector3(ToDxfX(rect.X), ToDxfY(rect.Y + rect.Height), 0),
                        rect.Width,
                        rect.Height);
                    _doc.AddEntity(dxfImage);
                }
            }
        }