Exemplo n.º 1
0
        private void Add(SKDocument pdf, XContainer container)
        {
            float width  = (float)container.Template.Width;
            float height = (float)container.Template.Height;

            using (SKCanvas canvas = pdf.BeginPage(width, height))
            {
                // Calculate x and y page scale factors.
                double scaleX = width / container.Template.Width;
                double scaleY = height / container.Template.Height;
                double scale  = Math.Min(scaleX, scaleY);

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

                // Draw container template contents to pdf graphics.
                if (container.Template.Background.A > 0)
                {
                    DrawBackgroundInternal(
                        canvas,
                        container.Template.Background,
                        Rect2.Create(0, 0, width / scale, height / scale));
                }

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

                // Draw page contents to pdf graphics.
                Draw(canvas, container, container.Data.Properties, container.Data.Record);
            }
        }
Exemplo n.º 2
0
        public void Create_FromVectors()
        {
            Rect2 result = Rect2.Create(
                new Vector2(100, 100),
                new Vector2(500, 300),
                new Vector2(900, 800));

            Assert.Equal(new Rect2(100, 100, 800, 700), result);
        }
Exemplo n.º 3
0
        public void Create_FromRects()
        {
            Rect2 result = Rect2.Create(
                new Rect2(100, 100, 100, 100),
                new Rect2(500, 300, 100, 100),
                new Rect2(150, 150, 750, 650));

            Assert.Equal(new Rect2(100, 100, 800, 700), result);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="container"></param>
        private void DrawBackgroundInternal(Graphics gfx, Container container)
        {
            Brush brush = ToSolidBrush(container.Background);
            var   rect  = Rect2.Create(0, 0, container.Width, container.Height);

            gfx.FillRectangle(
                brush,
                _scaleToPage(rect.X),
                _scaleToPage(rect.Y),
                _scaleToPage(rect.Width),
                _scaleToPage(rect.Height));
            brush.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="c"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        private void DrawBackground(Graphics g, ArgbColor c, double width, double height)
        {
            var brush = new SolidBrush(Color.FromArgb(c.A, c.R, c.G, c.B));
            var rect  = Rect2.Create(0, 0, width, height);

            g.FillRectangle(
                brush,
                (float)rect.X,
                (float)rect.Y,
                (float)rect.Width,
                (float)rect.Height);
            brush.Dispose();
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static GdiArc FromXArc(XPoint p1, XPoint p2, XPoint p3, XPoint p4, double dx, double dy)
        {
            double x1         = p1.X + dx;
            double y1         = p1.Y + dy;
            double x2         = p2.X + dx;
            double y2         = p2.Y + dy;
            double x3         = p3.X + dx;
            double y3         = p3.Y + dy;
            double x4         = p4.X + dx;
            double y4         = p4.Y + dy;
            var    rect       = Rect2.Create(x1, y1, x2, y2, dx, dy);
            double cx         = rect.X + rect.Width / 2.0;
            double cy         = rect.Y + rect.Height / 2.0;
            double radiusX    = cx - rect.X;
            double radiusY    = cy - rect.Y;
            double startAngle = Atan2(y3 - cy, x3 - cx);
            double endAngle   = Atan2(y4 - cy, x4 - cx);
            double sweepAngle = (endAngle - startAngle) * 180.0 / PI;

            if (sweepAngle < 0)
            {
                sweepAngle += 360;
            }

            startAngle *= 180.0 / PI;
            endAngle   *= 180.0 / PI;

            return(new GdiArc
            {
                X = rect.X,
                Y = rect.Y,
                Width = rect.Width,
                Height = rect.Height,
                RadiusX = radiusX,
                RadiusY = radiusY,
                StartAngle = startAngle,
                EndAngle = endAngle,
                SweepAngle = sweepAngle
            });
        }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tl"></param>
 /// <param name="br"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 private static Rect2 CreateRect(XPoint tl, XPoint br, double dx, double dy)
 {
     return(Rect2.Create(tl, br, dx, dy));
 }
Exemplo n.º 8
0
 private static Rect2 CreateRect(XPoint tl, XPoint br, double dx, double dy) => Rect2.Create(tl, br, dx, dy);
Exemplo n.º 9
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XText"/> shape.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetTextBounds(XText text, double dx, double dy)
 {
     return(Rect2.Create(text.TopLeft, text.BottomRight, dx, dy));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XEllipse"/> shape.
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetEllipseBounds(XEllipse ellipse, double dx, double dy)
 {
     return(Rect2.Create(ellipse.TopLeft, ellipse.BottomRight, dx, dy));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XRectangle"/> shape.
 /// </summary>
 /// <param name="rectangle"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetRectangleBounds(XRectangle rectangle, double dx, double dy)
 {
     return(Rect2.Create(rectangle.TopLeft, rectangle.BottomRight, dx, dy));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Get the bounding rectangle for <see cref="XImage"/> shape.
 /// </summary>
 /// <param name="image"></param>
 /// <param name="dx"></param>
 /// <param name="dy"></param>
 /// <returns></returns>
 public static Rect2 GetImageBounds(XImage image, double dx, double dy)
 {
     return(Rect2.Create(image.TopLeft, image.BottomRight, dx, dy));
 }
Exemplo n.º 13
0
        public void Create_FromRects_NullVectors_Infinite()
        {
            Rect2 result = Rect2.Create((IEnumerable <Vector2>)null);

            Assert.Equal(Rect2.Infinite, result);
        }
Exemplo n.º 14
0
        public void Draw(object ds, XText text, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var _ds = ds as CanvasDrawingSession;

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

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

            var brush = ToColor(text.Style.Stroke);

            var fontWeight = FontWeights.Normal;

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Bold))
            {
                fontWeight = FontWeights.Bold;
            }

            var fontStyle = Windows.UI.Text.FontStyle.Normal;

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Italic))
            {
                fontStyle = Windows.UI.Text.FontStyle.Italic;
            }

            var format = new CanvasTextFormat()
            {
                FontFamily   = text.Style.TextStyle.FontName,
                FontWeight   = fontWeight,
                FontStyle    = fontStyle,
                FontSize     = (float)text.Style.TextStyle.FontSize,
                WordWrapping = CanvasWordWrapping.NoWrap
            };

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

            var layout = new CanvasTextLayout(_ds, tbind, format, (float)rect.Width, (float)rect.Height);

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Underline))
            {
                layout.SetUnderline(0, tbind.Length, true);
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Test2d.FontStyleFlags.Strikeout))
            {
                layout.SetStrikethrough(0, tbind.Length, true);
            }

            switch (text.Style.TextStyle.TextHAlignment)
            {
            case TextHAlignment.Left:
                layout.HorizontalAlignment = CanvasHorizontalAlignment.Left;
                break;

            case TextHAlignment.Center:
                layout.HorizontalAlignment = CanvasHorizontalAlignment.Center;
                break;

            case TextHAlignment.Right:
                layout.HorizontalAlignment = CanvasHorizontalAlignment.Right;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            case TextVAlignment.Top:
                layout.VerticalAlignment = CanvasVerticalAlignment.Top;
                break;

            case TextVAlignment.Center:
                layout.VerticalAlignment = CanvasVerticalAlignment.Center;
                break;

            case TextVAlignment.Bottom:
                layout.VerticalAlignment = CanvasVerticalAlignment.Bottom;
                break;
            }

            _ds.DrawTextLayout(
                layout,
                new N.Vector2(
                    (float)rect.X,
                    (float)rect.Y),
                brush);

            layout.Dispose();
            format.Dispose();
        }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static WpfArc FromXArc(IArc arc, double dx, double dy)
        {
            var    p1      = Point2.Create(arc.Point1.X + dx, arc.Point1.Y + dy);
            var    p2      = Point2.Create(arc.Point2.X + dx, arc.Point2.Y + dy);
            var    p3      = Point2.Create(arc.Point3.X + dx, arc.Point3.Y + dy);
            var    p4      = Point2.Create(arc.Point4.X + dx, arc.Point4.Y + dy);
            var    rect    = Rect2.Create(p1, p2);
            var    center  = Point2.Create(rect.X + rect.Width / 2.0, rect.Y + rect.Height / 2.0);
            double offsetX = center.X - rect.X;
            double offsetY = center.Y - rect.Y;

            double minLenght = Max(offsetX, offsetY);

            double length1 = center.Distance(p3);
            double p3x     = p3.X + (p3.X - center.X) / length1 * minLenght;
            double p3y     = p3.Y + (p3.Y - center.Y) / length1 * minLenght;

            double length2 = center.Distance(p4);
            double p4x     = p4.X + (p4.X - center.X) / length2 * minLenght;
            double p4y     = p4.Y + (p4.Y - center.Y) / length2 * minLenght;

            p3.X = p3x;
            p3.Y = p3y;
            p4.X = p4x;
            p4.Y = p4y;

            var    p3i = MathHelpers.FindEllipseSegmentIntersections(rect, center, p3, true);
            var    p4i = MathHelpers.FindEllipseSegmentIntersections(rect, center, p4, true);
            Point2 start;
            Point2 end;

            if (p3i.Count == 1)
            {
                start = p3i.FirstOrDefault();
            }
            else
            {
                start = Point2.Create(p3.X, p3.Y);
            }

            if (p4i.Count == 1)
            {
                end = p4i.FirstOrDefault();
            }
            else
            {
                end = Point2.Create(p4.X, p4.Y);
            }

            double angle      = MathHelpers.AngleLineSegments(center, start, center, end);
            bool   isLargeArc = angle > 180.0;

            double helperLenght = 60.0;

            double lengthStart = center.Distance(start);
            double p3hx        = start.X + (start.X - center.X) / lengthStart * helperLenght;
            double p3hy        = start.Y + (start.Y - center.Y) / lengthStart * helperLenght;

            double lengthEnd = center.Distance(end);
            double p4hx      = end.X + (end.X - center.X) / lengthEnd * helperLenght;
            double p4hy      = end.Y + (end.Y - center.Y) / lengthEnd * helperLenght;

            p3.X = p3hx;
            p3.Y = p3hy;
            p4.X = p4hx;
            p4.Y = p4hy;

            return(new WpfArc()
            {
                P1 = p1,
                P2 = p2,
                P3 = p3,
                P4 = p4,
                Rect = rect,
                Center = center,
                Start = start,
                End = end,
                Radius = Size2.Create(offsetX, offsetY),
                IsLargeArc = isLargeArc,
                Angle = angle
            });
        }