Exemplo n.º 1
1
        /// <inheritdoc/>
        void Core2D.Interfaces.IProjectExporter.Save(string path, Core2D.Project.XProject project)
        {
            _outputPath = System.IO.Path.GetDirectoryName(path);
            var dxf = new DxfDocument(DxfVersion.AutoCad2010);

            Add(dxf, project);

            dxf.Save(path);
            ClearCache(isZooming: false);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        void Core2D.Interfaces.IProjectExporter.Save(string path, Core2D.Project.XDocument document)
        {
            using (var pdf = new PdfDocument())
            {
                var documentOutline = default(PdfOutline);

                foreach (var container in document.Pages)
                {
                    var page = Add(pdf, container);

                    if (documentOutline == null)
                    {
                        documentOutline = pdf.Outlines.Add(
                            document.Name,
                            page,
                            true,
                            PdfOutlineStyle.Regular,
                            XColors.Black);
                    }

                    documentOutline.Outlines.Add(
                        container.Name,
                        page,
                        true,
                        PdfOutlineStyle.Regular,
                        XColors.Black);
                }

                pdf.Save(path);
                ClearCache(isZooming: false);
            }
        }
Exemplo n.º 3
0
        private Ellipse CreateEllipticalArc(Core2D.Shapes.XArc arc, double dx, double dy)
        {
            var a = Core2D.Math.Arc.GdiArc.FromXArc(arc);

            double _cx = ToDxfX(a.X + dx + a.Width / 2.0);
            double _cy = ToDxfY(a.Y + dy + a.Height / 2.0);
            double minor = Math.Min(a.Height, a.Width);
            double major = Math.Max(a.Height, a.Width);
            double startAngle = -a.EndAngle;
            double endAngle = -a.StartAngle;
            double rotation = 0;

            if (a.Height > a.Width)
            {
                startAngle += 90;
                endAngle += 90;
                rotation = -90;
            }

            return new Ellipse()
            {
                Center = new Vector3(_cx, _cy, 0),
                MajorAxis = major,
                MinorAxis = minor,
                StartAngle = startAngle,
                EndAngle = endAngle,
                Rotation = rotation
            };
        }
Exemplo n.º 4
0
        private void Add(DxfDocument dxf, Core2D.Project.XDocument document)
        {
            foreach (var page in document.Pages)
            {
                var layout = new Layout(page.Name)
                {
                    PlotSettings = new PlotSettings()
                    {
                        PaperSizeName = $"{page.Template.Name}_({page.Template.Width}_x_{page.Template.Height}_MM)",
                        LeftMargin = 0.0,
                        BottomMargin = 0.0,
                        RightMargin = 0.0,
                        TopMargin = 0.0,
                        PaperSize = new Vector2(page.Template.Width, page.Template.Height),
                        Origin = new Vector2(0.0, 0.0),
                        PaperUnits = PlotPaperUnits.Milimeters,
                        PaperRotation = PlotRotation.NoRotation
                    }
                };
                dxf.Layouts.Add(layout);
                dxf.ActiveLayout = layout.Name;

                Add(dxf, page);
            }
        }
Exemplo n.º 5
0
 /// <inheritdoc/>
 void Core2D.Interfaces.IProjectExporter.Save(string path, Core2D.Project.XContainer container)
 {
     using (var pdf = new PdfDocument())
     {
         Add(pdf, container);
         pdf.Save(path);
     }
 }
Exemplo n.º 6
0
        private void Add(DxfDocument dxf, Core2D.Project.XContainer container)
        {
            if (container.Template != null)
            {
                _pageWidth = container.Template.Width;
                _pageHeight = container.Template.Height;
                Draw(dxf, container.Template, 0.0, 0.0, container.Data.Properties, container.Data.Record);
            }
            else
            {
                throw new NullReferenceException("Container template must be set.");
            }

            Draw(dxf, container, 0.0, 0.0, container.Data.Properties, container.Data.Record);
        }
Exemplo n.º 7
0
 private static void DrawLineCurveInternal(XGraphics gfx, XPen pen, bool isStroked, ref XPoint pt1, ref XPoint pt2, double curvature, Core2D.Style.CurveOrientation orientation, Core2D.Shape.PointAlignment pt1a, Core2D.Shape.PointAlignment pt2a)
 {
     if (isStroked)
     {
         var path = new XGraphicsPath();
         double p1x = pt1.X;
         double p1y = pt1.Y;
         double p2x = pt2.X;
         double p2y = pt2.Y;
         Core2D.Shapes.XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y);
         path.AddBezier(
             pt1.X, pt1.Y,
             p1x, p1y,
             p2x, p2y,
             pt2.X, pt2.Y);
         gfx.DrawPath(pen, path);
     }
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
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));
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="stroke"></param>
        /// <param name="rect"></param>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        /// <param name="cellWidth"></param>
        /// <param name="cellHeight"></param>
        /// <param name="isStroked"></param>
        private void DrawGridInternal(
            XGraphics gfx,
            XPen stroke,
            ref Core2D.Rect2 rect,
            double offsetX, double offsetY,
            double cellWidth, double cellHeight,
            bool isStroked)
        {
            double ox = rect.X;
            double oy = rect.Y;
            double sx = ox + offsetX;
            double sy = oy + offsetY;
            double ex = ox + rect.Width;
            double ey = oy + rect.Height;

            for (double x = sx; x < ex; x += cellWidth)
            {
                var p0 = new XPoint(
                    _scaleToPage(x),
                    _scaleToPage(oy));
                var p1 = new XPoint(
                    _scaleToPage(x),
                    _scaleToPage(ey));
                DrawLineInternal(gfx, stroke, isStroked, ref p0, ref p1);
            }

            for (double y = sy; y < ey; y += cellHeight)
            {
                var p0 = new XPoint(
                    _scaleToPage(ox),
                    _scaleToPage(y));
                var p1 = new XPoint(
                    _scaleToPage(ex),
                    _scaleToPage(y));
                DrawLineInternal(gfx, stroke, isStroked, ref p0, ref p1);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="color"></param>
 /// <param name="rect"></param>
 private void DrawBackgroundInternal(XGraphics gfx, Core2D.ArgbColor color, Core2D.Rect2 rect)
 {
     gfx.DrawRectangle(
         null,
         ToXSolidBrush(color),
         _scaleToPage(rect.X),
         _scaleToPage(rect.Y),
         _scaleToPage(rect.Width),
         _scaleToPage(rect.Height));
 }
Exemplo n.º 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="color"></param>
 /// <returns></returns>
 private static XColor ToXColor(Core2D.ArgbColor color)
 {
     return XColor.FromArgb(
         color.A,
         color.R,
         color.G,
         color.B);
 }
Exemplo n.º 13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="style"></param>
 /// <param name="scale"></param>
 /// <returns></returns>
 private static XPen ToXPen(Core2D.BaseStyle style, Func<double, double> scale)
 {
     var pen = new XPen(ToXColor(style.Stroke), XUnit.FromPresentation(style.Thickness));
     switch (style.LineCap)
     {
         case Core2D.LineCap.Flat:
             pen.LineCap = XLineCap.Flat;
             break;
         case Core2D.LineCap.Square:
             pen.LineCap = XLineCap.Square;
             break;
         case Core2D.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;
 }
Exemplo n.º 14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="container"></param>
 public void Save(string path, Core2D.Container container)
 {
     using (var pdf = new PdfDocument())
     {
         Add(pdf, container);
         pdf.Save(path);
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="project"></param>
        public void Save(string path, Core2D.Project project)
        {
            using (var pdf = new PdfDocument())
            {
                var projectOutline = default(PdfOutline);

                foreach (var document in project.Documents)
                {
                    var documentOutline = default(PdfOutline);

                    foreach (var container in document.Containers)
                    {
                        var page = Add(pdf, container);

                        if (projectOutline == null)
                        {
                            projectOutline = pdf.Outlines.Add(
                                project.Name,
                                page,
                                true,
                                PdfOutlineStyle.Regular,
                                XColors.Black);
                        }

                        if (documentOutline == null)
                        {
                            documentOutline = projectOutline.Outlines.Add(
                                document.Name,
                                page,
                                true,
                                PdfOutlineStyle.Regular,
                                XColors.Black);
                        }

                        documentOutline.Outlines.Add(
                            container.Name,
                            page,
                            true,
                            PdfOutlineStyle.Regular,
                            XColors.Black);
                    }
                }

                pdf.Save(path);
                ClearCache(isZooming: false);
            }
        }
Exemplo n.º 16
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);
         }
     }
 }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
0
 private void Add(DxfDocument dxf, Core2D.Project.XProject project)
 {
     foreach (var document in project.Documents)
     {
         Add(dxf, document);
     }
 }
Exemplo n.º 19
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);
         }
     }
 }
Exemplo n.º 20
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));
                }
            }
        }
Exemplo n.º 21
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);
                }
            }
        }
Exemplo n.º 22
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));
            }
        }
Exemplo n.º 23
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);
            }
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        private PdfPage Add(PdfDocument pdf, Core2D.Project.XContainer container)
        {
            // Create A3 page size with Landscape orientation.
            PdfPage pdfPage = pdf.AddPage();
            pdfPage.Size = PageSize.A3;
            pdfPage.Orientation = PageOrientation.Landscape;

            using (XGraphics gfx = XGraphics.FromPdfPage(pdfPage))
            {
                // Calculate x and y page scale factors.
                double scaleX = pdfPage.Width.Value / container.Template.Width;
                double scaleY = pdfPage.Height.Value / container.Template.Height;
                double scale = Math.Min(scaleX, scaleY);

                // Set scaling function.
                _scaleToPage = (value) => value * scale;

                // Draw container template contents to pdf graphics.
                if (container.Template.Background.A > 0)
                {
                    Fill(gfx, 0, 0, pdfPage.Width.Value / scale, pdfPage.Height.Value / scale, container.Template.Background);
                }

                // Draw template contents to pdf graphics.
                Draw(gfx, container.Template, 0.0, 0.0, container.Data.Properties, container.Data.Record);

                // Draw page contents to pdf graphics.
                Draw(gfx, container, 0.0, 0.0, container.Data.Properties, container.Data.Record);
            }

            return pdfPage;
        }
Exemplo n.º 26
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ds"></param>
 /// <param name="c"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 private void DrawBackground(CanvasDrawingSession ds, Core2D.ArgbColor c, double width, double height)
 {
     var color = Color.FromArgb(
         c.A,
         c.R,
         c.G,
         c.B);
     var rect = Core2D.Rect2.Create(0, 0, width, height);
     ds.FillRectangle(
         (float)rect.X,
         (float)rect.Y,
         (float)rect.Width,
         (float)rect.Height,
         color);
 }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pdf"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        private PdfPage Add(PdfDocument pdf, Core2D.Container container)
        {
            // create A4 page with landscape orientation
            PdfPage page = pdf.AddPage();
            page.Size = PageSize.A3;
            page.Orientation = PageOrientation.Landscape;

            using (XGraphics gfx = XGraphics.FromPdfPage(page))
            {
                // calculate x and y page scale factors
                double scaleX = page.Width.Value / container.Width;
                double scaleY = page.Height.Value / container.Height;
                double scale = Math.Min(scaleX, scaleY);

                // set scaling function
                _scaleToPage = (value) => value * scale;

                // draw container template contents to pdf graphics
                if (container.Template != null)
                {
                    if (container.Template.Background.A > 0)
                    {
                        DrawBackgroundInternal(
                            gfx,
                            container.Template.Background,
                            Core2D.Rect2.Create(0, 0, page.Width.Value / scale, page.Height.Value / scale));
                    }
                    Draw(gfx, container.Template, container.Properties, null);
                }

                // draw container contents to pdf graphics
                if (container.Background.A > 0)
                {
                    DrawBackgroundInternal(
                        gfx,
                        container.Background,
                        Core2D.Rect2.Create(0, 0, page.Width.Value / scale, page.Height.Value / scale));
                }
                Draw(gfx, container, container.Properties, null);
            }

            return page;
        }
Exemplo n.º 29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="project"></param>
 /// <returns></returns>
 private async Task CacheImages(Core2D.Project project)
 {
     var images = Core2D.Editor.GetAllShapes<Core2D.XImage>(project);
     if (images != null)
     {
         foreach (var image in images)
         {
             await CacheImage(image.Key);
         }
     }
 }
Exemplo n.º 30
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();
                }
            }
        }