Esempio n. 1
0
        public void BeginBox(XGraphics gfx, int number, string title)
        {
            XRect xRect = new XRect(0.0, 20.0, 300.0, 200.0);
            bool  flag  = number % 2 == 0;

            if (flag)
            {
                xRect.X = 295.0;
            }
            xRect.Y = (double)(40 + (number - 1) / 2 * 195);
            xRect.Inflate(-10.0, -10.0);
            XRect rect = xRect;

            rect.Offset(this.borderWidth, this.borderWidth);
            gfx.DrawRoundedRectangle(new XSolidBrush(this.shadowColor), rect, new XSize(23.0, 23.0));
            XLinearGradientBrush brush = new XLinearGradientBrush(xRect, this.backColor, this.backColor2, XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(this.borderPen, brush, xRect, new XSize(15.0, 15.0));
            xRect.Inflate(-5.0, -5.0);
            XFont font = new XFont("Verdana", 12.0, XFontStyle.Regular);

            gfx.DrawString(title, font, XBrushes.Navy, xRect, XStringFormats.TopCenter);
            xRect.Inflate(-10.0, -5.0);
            xRect.Y      += 20.0;
            xRect.Height -= 20.0;
            this.state    = gfx.Save();
            gfx.TranslateTransform(xRect.X, xRect.Y);
        }
Esempio n. 2
0
        public void DrawRect(Rect bounds, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            if (style.HasFill)
            {
                if (style.CornerRadius.TopLeft > 0)
                {
                    _g.DrawRoundedRectangle(style.Fill.ToXBrush(bounds.Width, bounds.Height), bounds.ToXRect(), new XSize(style.CornerRadius.TopLeft, style.CornerRadius.TopLeft));
                }
                else
                {
                    _g.DrawRectangle(style.Fill.ToXBrush(bounds.Width, bounds.Height), bounds.ToXRect());
                }
            }

            if (style.HasStroke)
            {
                if (style.CornerRadius.TopLeft > 0)
                {
                    _g.DrawRoundedRectangle(new XPen(style.Stroke.ToXColor(), style.StrokeThickness.Left), bounds.ToXRect(), new XSize(style.CornerRadius.TopLeft, style.CornerRadius.TopLeft));
                }
                else
                {
                    _g.DrawRectangle(new XPen(style.Stroke.ToXColor(), style.StrokeThickness.Left), bounds.ToXRect());
                }
            }
        }
Esempio n. 3
0
        private void BeginBox(XGraphics gfx, int number, string title)
        {
            const int dEllipse = 15;
            XRect     rect     = new XRect(0, 20, 300, 200);

            if (number % 2 == 0)
            {
                rect.X = 300 - 5;
            }
            rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
            rect.Inflate(-10, -10);
            XRect rect2 = rect;

            rect2.Offset(2, 2);
            XColor xColor1 = XColors.DarkGoldenrod;
            XColor xColor2 = XColors.Chocolate;

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromArgb(9, XColors.DarkGoldenrod)), rect2, new XSize(dEllipse + 8, dEllipse + 8));
            XLinearGradientBrush brush = new XLinearGradientBrush(rect, xColor1, xColor2, XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(brush, rect, new XSize(dEllipse, dEllipse));
            rect.Inflate(-5, -5);
            XFont font = new XFont("Verdana", 14, XFontStyle.Bold);

            gfx.DrawString(title, font, XBrushes.Black, rect, XStringFormats.TopCenter);
            rect.Inflate(-10, -5);
            rect.Y      += 20;
            rect.Height -= 20;
            gfx.Save();
            gfx.TranslateTransform(rect.X, rect.Y);
        }
Esempio n. 4
0
    public void BeginBox(XGraphics gfx, int number, string title)
    {
        const int dEllipse = 15;
        XRect     rect     = new XRect(0, 20, 300, 200);

        if (number % 2 == 0)
        {
            rect.X = 300 - 5;
        }
        rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
        rect.Inflate(-10, -10);
        XRect rect2 = rect;

        rect2.Offset(this.BorderWidth, this.BorderWidth);
        gfx.DrawRoundedRectangle(new XSolidBrush(this.ShadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8));
        XLinearGradientBrush brush = new XLinearGradientBrush(rect, this.BackColor, this.BackColor2, XLinearGradientMode.Vertical);

        gfx.DrawRoundedRectangle(this.BorderPen, brush, rect, new XSize(dEllipse, dEllipse));
        rect.Inflate(-5, -5);

        XFont font = new XFont("Verdana", 12, XFontStyle.Regular);

        gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter);

        rect.Inflate(-10, -5);
        rect.Y      += 20;
        rect.Height -= 20;

        this.state = gfx.Save();
        gfx.TranslateTransform(rect.X, rect.Y);
    }
Esempio n. 5
0
        public void DrawHeader(XGraphics gfx)
        {
            XRect userDetailsRect = new XRect(20, page.Height * 0.05, quaterWidth, page.Height * 0.075);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                                     userDetailsRect,
                                     new XSize(20, 20));

            XRect innerRect = new XRect(userDetailsRect.X + 10, userDetailsRect.Y + 10,
                                        userDetailsRect.Height - 20, userDetailsRect.Height - 20);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.LightGray)),
                                     innerRect,
                                     new XSize(10, 10));

            gfx.DrawString("Name : " + userProfile.Name, new XFont("Arial", 10), XBrushes.Black, 35, innerRect.Y + 10);
            gfx.DrawString("RB ID : " + userProfile.RBID.Replace(",", ""), new XFont("Arial", 10), XBrushes.Black, 35, innerRect.Y + 30);

            XImage headerImage = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Redback 3D logo.png");

            gfx.DrawImage(headerImage, new XPoint((quaterWidth * 2.5) - (headerImage.PixelWidth / 2), page.Height * 0.075));

            XSolidBrush brush = new XSolidBrush();
            double      score = Convert.ToDouble(userProfile.Score);

            if (score <= 33)
            {
                brush = new XSolidBrush(XColors.Red);
            }
            else if (score > 33 && score <= 66)
            {
                brush = new XSolidBrush(XColor.FromArgb(255, 255, 190, 0));
            }
            else
            {
                brush = new XSolidBrush(XColors.Green);
            }

            XRect scoreRect = new XRect((quaterWidth * 3) - 20, page.Height * 0.05, quaterWidth, page.Height * 0.075);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                                     scoreRect,
                                     new XSize(20, 20));

            XRect innerRectScore = new XRect(scoreRect.X + (scoreRect.Width - 50), scoreRect.Y + 10,
                                             scoreRect.Height - 20, scoreRect.Height - 20);

            gfx.DrawRoundedRectangle(brush,
                                     innerRectScore,
                                     new XSize(10, 10));

            gfx.DrawString("Overhead Squat : ", new XFont("Arial", 10),
                           XBrushes.Black, scoreRect.X + 10, scoreRect.Y + 35);

            gfx.DrawString(userProfile.Score + "%", new XFont("Arial", 10),
                           XBrushes.Black, innerRectScore.X + 5, innerRectScore.Y + 25);
        }
Esempio n. 6
0
        private void DrawRoundedRectangle(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawRoundedRectangle");
            XPen pen = new XPen(XColors.RoyalBlue, 3.1415926535897931);

            gfx.DrawRoundedRectangle(pen, 10, 0, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(XBrushes.Orange, 130, 0, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(pen, XBrushes.Orange, 10, 80, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(pen, XBrushes.Orange, 150, 80, 60, 60, 20, 20);
            base.EndBox(gfx);
        }
Esempio n. 7
0
        void RenderRoundedRectangles(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPen pen = new XPen(XColors.RoyalBlue, Math.PI);

            gfx.DrawRoundedRectangle(pen, 10, 0, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(XBrushes.Orange, 130, 0, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(pen, XBrushes.Orange, 10, 80, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(pen, XBrushes.Orange, 150, 80, 60, 60, 20, 20);
        }
Esempio n. 8
0
        public void DrawRoundRectangle(IPen pen, IBrush brush, int x, int y, int width, int height, int round)
        {
            if (brush is PdfBrush)
            {
                Graphics.DrawRoundedRectangle((XBrush)brush.Raw, x, y, width, height, round, round);
            }

            if (brush is PdfPen)
            {
                Graphics.DrawRoundedRectangle((XPen)pen.Raw, x, y, width, height, round, round);
            }
        }
Esempio n. 9
0
        static void DrawRoundedRectangle(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawRoundedRectangle");

            XPen pen = new XPen(XColors.RoyalBlue, System.Math.PI);

            gfx.DrawRoundedRectangle(pen, 10, 0, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(XBrushes.Orange, 130, 0, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(pen, XBrushes.Orange, 10, 80, 100, 60, 30, 20);
            gfx.DrawRoundedRectangle(pen, XBrushes.Orange, 150, 80, 60, 60, 20, 20);

            EndBox(gfx);
        }
Esempio n. 10
0
        private void Header()
        {
            gfx.DrawImage(identifier, new XRect(pageLeftRightMargin, actualHeight, identifier.PixelWidth / 6f, identifier.PixelHeight / 6f));

            double unitMargin = 2;
            double x          = 360;
            double y          = pageTopMargin;
            double width      = 180;
            double height     = unitNameFont.Height * 2 + unitMargin * 2;

            var unitRectangleSize = new XRect(x, y, width, height);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromArgb(0xFF85A314)), unitRectangleSize, new XSize(10, 10));

            x += unitMargin; y += unitMargin;
            DrawSpecialSingleLineString(Info.Unit?.NameFirstLine ?? string.Empty, unitNameFont, XStringFormats.TopLeft, new XRect(x, y, width, unitNameFont.Height), XBrushes.White);
            DrawSpecialSingleLineString(Info.Unit?.NameSecondLine ?? string.Empty, unitNameFont, XStringFormats.TopLeft, new XRect(x, y + unitNameFont.Height, width, unitNameFont.Height), XBrushes.White);


            y = pageTopMargin + unitRectangleSize.Height + unitMargin;

            foreach (string subline in Info.Unit?.SubtextLines ?? new string[0])
            {
                DrawSpecialSingleLineString(subline, unitSecondaryFont, XStringFormats.TopLeft, new XRect(x, y, width, unitSecondaryFont.Height));
                y += unitSecondaryFont.Height;
            }

            actualHeight = pageTopMargin + identifier.PixelHeight / 6 + 40;
            DrawSpecialSingleLineString($"{Info.City ?? string.Empty}, {Info.Date.ToString("dd.MM.yyyy")} r.", normalFont, XStringFormats.TopRight);
        }
        /// <summary>
        /// Demonstrates the use of XGraphics.DrawRoundedRectangle.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

#if DEBUG
            gfx.WriteComment("begin DrawRoundedRectangle");
#endif
            // Stroke rounded rectangle
            gfx.DrawRoundedRectangle(properties.Pen1.Pen, 50, 100, 450, 150, 50, 30);
#if DEBUG
            gfx.WriteComment("end DrawRoundedRectangle");
#endif

            // Fill rounded rectangle
            gfx.DrawRoundedRectangle(properties.Brush2.Brush, new Rectangle(50, 300, 450, 150), new SizeF(30, 20));

            // Stroke and fill rounded rectangle
            gfx.DrawRoundedRectangle(properties.Pen2.Pen, properties.Brush2.Brush,
                                     new XRect(50, 500, 450, 150), new XSize(75, 75));
        }
        private void DrawForAndroid(XGraphics page, Switch toggleSwitch, XRect bounds, double scaleFactor)
        {
            var thumbColor = toggleSwitch.ThumbColor != default ? toggleSwitch.ThumbColor : Color.WhiteSmoke;

            if (toggleSwitch.IsToggled)
            {
                var onColor = toggleSwitch.OnColor != default ? toggleSwitch.OnColor : Color.DodgerBlue;
                page.DrawRoundedRectangle(onColor.ToXBrush(), bounds.X, bounds.Y + bounds.Height * 0.25,
                                          2 * bounds.Height, bounds.Height * 0.5, bounds.Height / 2, bounds.Height / 2);
                page.DrawEllipse(thumbColor.ToXBrush(), bounds.X + bounds.Height * 1.1, bounds.Y + bounds.Height * 0.1,
                                 bounds.Height * 0.8, bounds.Height * 0.8);
            }
            else
            {
                page.DrawRoundedRectangle(Color.DarkGray.ToXBrush(), bounds.X, bounds.Y + bounds.Height * 0.25,
                                          2 * bounds.Height, bounds.Height * 0.5, bounds.Height / 2, bounds.Height / 2);
                page.DrawEllipse(Color.LightGray.ToXBrush(), bounds.X + bounds.Height * 0.1,
                                 bounds.Y + bounds.Height * 0.1, bounds.Height * 0.8, bounds.Height * 0.8);
            }
        }
        private void DrawForUWP(XGraphics page, Switch toggleSwitch, XRect bounds, double scaleFactor)
        {
            var thumbColor = toggleSwitch.ThumbColor != default ? toggleSwitch.ThumbColor : Color.WhiteSmoke;

            if (toggleSwitch.IsToggled)
            {
                var onColor = toggleSwitch.OnColor != default ? toggleSwitch.OnColor : Color.DodgerBlue;
                page.DrawRoundedRectangle(onColor.ToXBrush(), bounds.X, bounds.Y, 2 * bounds.Height, bounds.Height,
                                          bounds.Height, bounds.Height);
                page.DrawEllipse(thumbColor.ToXBrush(), bounds.X + bounds.Height * 1.2, bounds.Y + bounds.Height * 0.2,
                                 bounds.Height * 0.6, bounds.Height * 0.6);
            }
            else
            {
                page.DrawRoundedRectangle(new XPen(XColors.LightGray, scaleFactor), bounds.X, bounds.Y,
                                          2 * bounds.Height, bounds.Height, bounds.Height, bounds.Height);

                page.DrawEllipse(Color.Black.ToXBrush(), bounds.X + bounds.Height * 0.2, bounds.Y + bounds.Height * 0.2,
                                 bounds.Height * 0.6, bounds.Height * 0.6);
            }
        }
        private void DrawForiOS(XGraphics page, Switch toggleSwitch, XRect bounds, double scaleFactor)
        {
            var thumbColor = toggleSwitch.ThumbColor != default ? toggleSwitch.ThumbColor : Color.WhiteSmoke;

            if (toggleSwitch.IsToggled)
            {
                var onColor = toggleSwitch.OnColor != default ? toggleSwitch.OnColor : Color.Green;
                page.DrawRoundedRectangle(onColor.ToXBrush(), bounds.X, bounds.Y, 2 * bounds.Height, bounds.Height,
                                          bounds.Height, bounds.Height);
                page.DrawEllipse(thumbColor.ToXBrush(), bounds.X + bounds.Height * 1.1, bounds.Y + bounds.Height * 0.1,
                                 bounds.Height * 0.8, bounds.Height * 0.8);
            }
            else
            {
                page.DrawRoundedRectangle(new XPen(XColors.LightGray, scaleFactor), bounds.X, bounds.Y,
                                          2 * bounds.Height, bounds.Height, bounds.Height, bounds.Height);

                page.DrawEllipse(new XPen(Color.LightGray.ToXColor(), scaleFactor), bounds.X + bounds.Height * 0.1,
                                 bounds.Y + bounds.Height * 0.1, bounds.Height * 0.8, bounds.Height * 0.8);
            }
        }
Esempio n. 15
0
        public void Draw(XPoint basePoint, XRect baseRect, XImage image)
        {
            XFont headerFont = new XFont("Arial", 16);
            XFont subfont    = new XFont("Arial", 10);
            char  degree     = Convert.ToChar('\u00b0');

            gfx.DrawString(parameterLeft.Name.Substring(5, parameterLeft.Name.Length - 5), headerFont, XBrushes.Black, basePoint, XStringFormats.Center);
            gfx.DrawString(parameterLeft.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(-25, baseRect.Height * 0.05), XStringFormats.Center);
            gfx.DrawString(parameterRight.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(25, baseRect.Height * 0.05), XStringFormats.Center);

            XBrush brush = XBrushes.Black;

            if (parameterLeft.LSI >= 75)
            {
                brush = XBrushes.Green;
            }
            else
            {
                brush = XBrushes.Gold;
            }

            gfx.DrawRoundedRectangle(brush,
                                     new XRect(basePoint + new XPoint(-baseRect.Width * 0.05, baseRect.Height * 0.075),
                                               new XSize(baseRect.Width * 0.1, baseRect.Height * 0.075)),
                                     new XSize(10, 10));
            gfx.DrawString(parameterLeft.LSI.ToString("0") + "%",
                           subfont,
                           XBrushes.Black,
                           basePoint + new XPoint(baseRect.Width * -0.025, baseRect.Height * 0.125));

            XSolidBrush blue   = new XSolidBrush(XColor.FromArgb(127, 0, 0, 255));
            XSolidBrush yellow = new XSolidBrush(XColor.FromArgb(127, 255, 255, 0));

            XPoint top    = new XPoint(basePoint.X - 20, basePoint.Y + baseRect.Height * 0.2);
            XPoint bottom = new XPoint(basePoint.X - 20, basePoint.Y + baseRect.Height * 0.8);

            XPoint leftRectPoint = Interpolate(bottom, top, -parameterLeft.Percentage);
            XRect  leftBar       = new XRect(leftRectPoint, new XSize(20, bottom.Y - leftRectPoint.Y));

            gfx.DrawRectangle(blue, leftBar);

            XPoint rigthRectPoint = Interpolate(bottom, top, -parameterRight.Percentage);
            XRect  rightBar       = new XRect(rigthRectPoint + new XPoint(30, 0), new XSize(20, bottom.Y - rigthRectPoint.Y));

            gfx.DrawRectangle(yellow, rightBar);

            gfx.DrawString("L", subfont, XBrushes.Black, bottom + new XPoint(5, -2));
            gfx.DrawString("R", subfont, XBrushes.Black, bottom + new XPoint(35, -2));

            gfx.DrawImage(image, new XRect(bottom.X, bottom.Y, 50, 50));
            image.Dispose();
        }
        private static void CrateBack(XUnit pageWdith, XUnit pageHeight, PdfDocument document, string currentCardType)
        {
            PdfPage page = document.AddPage();

            page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
            page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


            XGraphics gfx = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH = PdfFontEncoding.Unicode;
            //gfx.MFEH = PdfFontEmbedding.Default;

            gfx.ScaleAtTransform(-1, 1, page.Width / 2, page.Height / 2);

            XFont font = new XFont("Verdana", 13, XFontStyle.Regular);



            var costSize = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);

            var costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);



            var actionRect     = new XRect(costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), pageHeight * 2, costSize.Height * 2);
            var actionTextRect = actionRect;

            actionTextRect.Height = costSize.Height;
            actionTextRect.Offset(new XUnit(3, XGraphicsUnit.Millimeter), 0);

            gfx.TranslateTransform(new XUnit(3, XGraphicsUnit.Millimeter), 0);
            gfx.RotateAtTransform(90, actionRect.TopLeft);

            gfx.DrawRoundedRectangle(XPens.MidnightBlue, XBrushes.DarkSlateBlue, actionRect, new XSize(10, 10));

            gfx.ScaleAtTransform(1, -1, actionTextRect.Center);

            gfx.DrawString(currentCardType, font, XBrushes.White,
                           actionTextRect, XStringFormats.TopLeft);
            gfx.ScaleAtTransform(1, -1, actionTextRect.Center);


            gfx.RotateAtTransform(-90, actionRect.TopLeft);
            gfx.TranslateTransform(new XUnit(-3, XGraphicsUnit.Millimeter), 0);

            var circle = new XRect(new XUnit(-3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(10, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter));

            gfx.DrawEllipse(XPens.MidnightBlue, XBrushes.White, circle);
        }
Esempio n. 17
0
        void DrawPentaInfoBox(XGraphics gfx, XPoint point, XImage image, Parameter parameter)
        {
            double val   = parameter.Value;
            string str   = parameter.Name;
            XBrush brush = ChooseBrushColor(parameter.Percentage,
                                            parameter.RedVal,
                                            parameter.AmberVal);
            XSize ellipseSize = new XSize(10, 10);

            gfx.DrawRoundedRectangle(brush, new XRect(point.X, point.Y, 50, 50), ellipseSize);
            gfx.DrawString(str, new XFont("Arial", 12), XBrushes.White, point + new XPoint(0, 60));
            gfx.DrawString(val.ToString() + "%", new XFont("Arial", 12), XBrushes.White, point + new XPoint(10, 30));
            gfx.DrawImage(image, new XRect(point + new XPoint(50, 0), new XSize(50, 50)));
        }
Esempio n. 18
0
        private void RenderLabel(XGraphics gfx)
        {
            XSize  lSize = new XSize(XUnit.FromMillimeter(pageSettings.LabelSize.Width), XUnit.FromMillimeter(pageSettings.LabelSize.Height));
            XPoint lPt   = new XPoint(0, 0);
            //Just draw each side for all labels, dont care if they overlap...
            XRect rect = new XRect(lPt, lSize);

            gfx.DrawRoundedRectangle(XPens.Black, rect, new XSize(XUnit.FromMillimeter(pageSettings.Corner.Width), XUnit.FromMillimeter(pageSettings.Corner.Height)));

            foreach (LabelItem item in labelItems)
            {
                item.Render(gfx, lPt);
            }
        }
Esempio n. 19
0
        public void DrawBarCharts(XGraphics gfx)
        {
            XPoint backgroundPoint = new XPoint(20, page.Height * 0.585);
            XRect  backgroundRect  = new XRect(backgroundPoint.X, backgroundPoint.Y, page.Width - 40, page.Height * 0.41);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                                     backgroundRect,
                                     new XSize(40, 40));

            DoubleBar ShoulderFlexionBar = new DoubleBar(userParameters["LEFT Shoulder Flexion"], userParameters["RIGHT Shoulder Flexion"], gfx);

            ShoulderFlexionBar.Draw(new XPoint(quaterWidth * 0.5 - 10, backgroundPoint.Y + 20),
                                    backgroundRect,
                                    XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Shoulder Flexion.png"));

            DoubleBar hipFlexionBar = new DoubleBar(userParameters["LEFT Hip Flexion"], userParameters["RIGHT Hip Flexion"], gfx);

            hipFlexionBar.Draw(new XPoint(quaterWidth * 2 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20),
                               backgroundRect,
                               XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Hip Flexion.png"));

            DoubleBar kneeFlexionBar = new DoubleBar(userParameters["LEFT Knee Flexion"], userParameters["RIGHT Knee Flexion"], gfx);

            kneeFlexionBar.Draw(new XPoint(quaterWidth * 3 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20),
                                backgroundRect,
                                XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Knee Flexion.png"));


            DoubleBar ankleFlexionBar = new DoubleBar(userParameters["LEFT Ankle Flexion"], userParameters["RIGHT Ankle Flexion"], gfx);

            ankleFlexionBar.Draw(new XPoint(quaterWidth * 4 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20),
                                 backgroundRect,
                                 XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Ankle Flexion.png"));


            XPoint top    = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.2);
            XPoint bottom = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.8);

            for (int i = 11; i > 0; i--)
            {
                float increment = -i * 0.1f;

                XPoint percentagePoint = Interpolate(top, bottom, increment);
                gfx.DrawString(((11 - i) * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, percentagePoint + new XPoint(5, 0));
                gfx.DrawLine(XPens.Black, percentagePoint, percentagePoint + new XPoint(backgroundRect.Width, 0));
            }
        }
Esempio n. 20
0
        private void RenderGrid(XGraphics gfx)
        {
            int x, y;

            //Create the grid
            for (x = 0; x < pageSettings.LabelsX; x++)
            {
                for (y = 0; y < pageSettings.LabelsY; y++)
                {
                    XSize  sSize = new XSize(XUnit.FromMillimeter(pageSettings.Spacing.Width), XUnit.FromMillimeter(pageSettings.Spacing.Height));
                    XSize  lSize = new XSize(XUnit.FromMillimeter(pageSettings.LabelSize.Width), XUnit.FromMillimeter(pageSettings.LabelSize.Height));
                    XPoint lPt   = new XPoint(XUnit.FromMillimeter(pageSettings.FirstLabel.X), XUnit.FromMillimeter(pageSettings.FirstLabel.Y));
                    XPoint pt    = new XPoint(x * (lSize.Width + sSize.Width) + lPt.X, y * (lSize.Height + sSize.Height) + lPt.Y);

                    //Just draw each side for all labels, dont care if they overlap...
                    XRect rect = new XRect(pt, lSize);
                    gfx.DrawRoundedRectangle(XPens.Black, rect, new XSize(XUnit.FromMillimeter(pageSettings.Corner.Width), XUnit.FromMillimeter(pageSettings.Corner.Height)));

                    //foreach (LabelItem item in labelItems)
                    //    item.Render(gfx, pt);
                }
            }
        }
Esempio n. 21
0
        public void DrawPentagon(XGraphics gfx)
        {
            XRect backgroundRect = new XRect(20, page.Height * 0.15, page.Width - 40, page.Height * 0.425);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                                     backgroundRect,
                                     new XSize(40, 40));

            double c1 = Math.Cos((2 * Math.PI) / 5);
            double c2 = Math.Cos(Math.PI / 5);
            double s1 = Math.Sin((2 * Math.PI) / 5);
            double s2 = Math.Sin((4 * Math.PI) / 5);

            XPoint[] pentatPoints = new XPoint[5];

            XPoint center = new XPoint(page.Width * 0.5, page.Height * 0.425);
            XPoint top    = new XPoint(page.Width * 0.5, page.Height * 0.25);

            double lengthOfLine = Distance(top, center);
            XPoint bottomLeft   = new XPoint(center.X + (lengthOfLine * -s2), center.Y - (lengthOfLine * -c2));
            XPoint bottomRight  = new XPoint(center.X + (lengthOfLine * s2), center.Y - (lengthOfLine * -c2));
            XPoint topLeft      = new XPoint(center.X + (lengthOfLine * -s1), center.Y - (lengthOfLine * c1));
            XPoint topRight     = new XPoint(center.X + (lengthOfLine * s1), center.Y - (lengthOfLine * c1));

            pentatPoints[0] = top;
            pentatPoints[1] = topRight;
            pentatPoints[2] = bottomRight;
            pentatPoints[3] = bottomLeft;
            pentatPoints[4] = topLeft;

            gfx.DrawPolygon(XBrushes.DimGray, pentatPoints, XFillMode.Winding);

            XPen yellowPen    = new XPen(XColors.Yellow, 2.5);
            XPen greenPen     = new XPen(XColors.Green, 2.5);
            XPen perimeterPen = XPens.LightGray;
            XPen redPen       = new XPen(XColors.Red, 2.5);

            //center out
            gfx.DrawLine(greenPen, center, top);
            gfx.DrawLine(greenPen, center, bottomLeft);
            gfx.DrawLine(greenPen, center, bottomRight);
            gfx.DrawLine(greenPen, center, topLeft);
            gfx.DrawLine(greenPen, center, topRight);

            XBrush brush       = XBrushes.Black;
            XSize  size        = new XSize(50, 50);
            XSize  ellipseSize = new XSize(10, 10);
            //images
            XImage leftKneeImg    = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Left Knee Stability.png");
            XImage rightKneeImg   = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Right Knee Stability.png");
            XImage tibia_spineImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Tibia Spine Angle.png");
            XImage dosImg         = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Depth of Squat.png");
            XImage pelvicImg      = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Pelvic Stability.png");

            //infoboxes
            DrawPentaInfoBox(gfx, top + new XPoint(-50, -75), tibia_spineImg, userParameters["Tibia / Spine Angle"]);
            DrawPentaInfoBox(gfx, topLeft + new XPoint(-100, -35), leftKneeImg, userParameters["LEFT Knee Stability"]);
            DrawPentaInfoBox(gfx, topRight + new XPoint(25, -35), rightKneeImg, userParameters["RIGHT Knee Stability"]);
            DrawPentaInfoBox(gfx, bottomRight + new XPoint(25, -60), pelvicImg, userParameters["Pelvic Stability"]);
            DrawPentaInfoBox(gfx, bottomLeft + new XPoint(-125, -60), dosImg, userParameters["Depth of Squat"]);

            //percentage Lines
            gfx.DrawString(0 + "%", new XFont("Arial", 10), XBrushes.Black, center + new XPoint(5, 0));
            for (int i = 10; i > 0; i--)
            {
                float increment = -i * 0.1f;

                gfx.DrawString((i * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, Interpolate(center, top, increment) + new XPoint(5, 0));

                gfx.DrawLine(perimeterPen, Interpolate(center, topLeft, increment), Interpolate(center, top, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, top, increment), Interpolate(center, topRight, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, topRight, increment), Interpolate(center, bottomRight, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, bottomRight, increment), Interpolate(center, bottomLeft, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, bottomLeft, increment), Interpolate(center, topLeft, increment));
            }

            XPoint centerTibia           = Interpolate(center, top, -userParameters["Tibia / Spine Angle"].Percentage);
            XPoint centerRightKnee       = Interpolate(center, topRight, -userParameters["RIGHT Knee Stability"].Percentage);
            XPoint centerPelvicStability = Interpolate(center, bottomRight, -userParameters["Pelvic Stability"].Percentage);
            XPoint centerDos             = Interpolate(center, bottomLeft, -userParameters["Depth of Squat"].Percentage);
            XPoint centerLeftKnee        = Interpolate(center, topLeft, -userParameters["LEFT Knee Stability"].Percentage);

            gfx.DrawLine(redPen, center, Interpolate(center, top, -userParameters["Tibia / Spine Angle"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, topRight, -userParameters["RIGHT Knee Stability"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, bottomRight, -userParameters["Pelvic Stability"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, bottomLeft, -userParameters["Depth of Squat"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, topLeft, -userParameters["LEFT Knee Stability"].RedVal));

            gfx.DrawPolygon(new XPen(XColor.FromArgb(1, 0, 255, 255)),
                            new XSolidBrush(XColor.FromArgb(127, 255, 255, 0)),
                            new XPoint[] { centerTibia, centerRightKnee, centerPelvicStability, centerDos, centerLeftKnee },
                            XFillMode.Alternate);
        }
Esempio n. 22
0
        /// <summary>
        /// Draws all charts inside the ChartFrame.
        /// </summary>
        public void Draw(XGraphics gfx)
        {
            // Draw frame of ChartFrame. First shadow frame.
            int dx = 5;
            int dy = 5;

            gfx.DrawRoundedRectangle(XBrushes.Gainsboro,
                                     this.location.X + dx, this.location.Y + dy,
                                     this.size.Width, this.size.Height, 20, 20);

            XRect chartRect            = new XRect(this.location.X, this.location.Y, this.size.Width, this.size.Height);
            XLinearGradientBrush brush = new XLinearGradientBrush(chartRect, XColor.FromArgb(0xFFD0DEEF), XColors.White,
                                                                  XLinearGradientMode.Vertical);
            XPen penBorder = new XPen(XColors.SteelBlue, 2.5);

            gfx.DrawRoundedRectangle(penBorder, brush,
                                     this.location.X, this.location.Y, this.size.Width, this.size.Height,
                                     15, 15);

            XGraphicsState state = gfx.Save();

            gfx.TranslateTransform(this.location.X, this.location.Y);

            // Calculate rectangle for all charts. Y-Position will be moved for each chart.
            int   charts          = this.chartList.Count;
            uint  dxChart         = 20;
            uint  dyChart         = 20;
            uint  dyBetweenCharts = 30;
            XRect rect            = new XRect(dxChart, dyChart,
                                              this.size.Width - 2 * dxChart,
                                              (this.size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts);

            // draw each chart in list
            foreach (Chart chart in this.chartList)
            {
                RendererParameters parms = new RendererParameters(gfx, rect);
                parms.DrawingItem = chart;

                ChartRenderer renderer = GetChartRenderer(chart, parms);
                renderer.Init();
                renderer.Format();
                renderer.Draw();

                rect.Y += rect.Height + dyBetweenCharts;
            }
            gfx.Restore(state);

//      // Calculate rectangle for all charts. Y-Position will be moved for each chart.
//      int charts = this.chartList.Count;
//      uint dxChart = 0;
//      uint dyChart = 0;
//      uint dyBetweenCharts = 0;
//      XRect rect = new XRect(dxChart, dyChart,
//        this.size.Width - 2 * dxChart,
//        (this.size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts);
//
//      // draw each chart in list
//      foreach (Chart chart in this.chartList)
//      {
//        RendererParameters parms = new RendererParameters(gfx, rect);
//        parms.DrawingItem = chart;
//
//        ChartRenderer renderer = GetChartRenderer(chart, parms);
//        renderer.Init();
//        renderer.Format();
//        renderer.Draw();
//
//        rect.Y += rect.Height + dyBetweenCharts;
//      }
        }
Esempio n. 23
0
        public void CreatePDF(Recept recept)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();
            XGraphics   gfx      = XGraphics.FromPdfPage(page);
            //-------------------------------------------//-------------------------------------------

            XFont          font      = new XFont("Times New Roman", 15, XFontStyle.Bold);
            XTextFormatter tf        = new XTextFormatter(gfx);
            var            lineColor = XPens.DarkGreen;
            int            y         = 60;

            //---------------------כותרת----------------

            gfx.DrawString("madicel center ", new XFont("Times New Roman", 15, XFontStyle.Bold)
                           , XBrushes.Black, new XRect(page.Width / 2, 5, 5, 0), XStringFormats.TopCenter);

            gfx.DrawString("recept No: " + recept.ReceptId, new XFont("Times New Roman", 15, XFontStyle.Bold)
                           , XBrushes.Black, new XRect(page.Width - 25, 5, 5, 0), XStringFormats.TopRight);

            gfx.DrawString(recept.Date.ToShortDateString(), new XFont("Times New Roman", 15, XFontStyle.Bold)
                           , XBrushes.Black, new XRect(5, 5, 5, 0), XStringFormats.TopLeft);

            gfx.DrawString("Recept", new XFont("Times New Roman", 30, XFontStyle.Bold)
                           , XBrushes.Black, new XRect(0, y, page.Width, 0), XStringFormats.Center);

            //-------------------Physician------------------------
            Physician Dr     = GetPhysician(recept.PhysicianID);
            string    drName = "Doctor " + Dr.FirstName + " " + Dr.LastName + ".\n" +
                               "phone: " + Dr.Phone + "\n" +
                               "email: " + Dr.Email + "\n" +
                               "address: " + Dr.Address;

            //---------------------Patient----------------------
            Patient patient       = GetPatient(recept.PatientID);
            string  patientDetail = patient.Sex == Sex.MALE ? "Mr " : "Miss ";

            patientDetail += patient.FirstName + " " + patient.LastName + ".\n";
            patientDetail += "id: " + patient.ID + "\n" +
                             "sex: " + patient.Sex + "      Age: " + patient.Age + "\n" +
                             "address: " + patient.Address;

            //----------------------Drug---------------------
            Drug   drug          = GetDrug(recept.IdCodeOfDrug);
            string receptDetail1 = "Drug name: " + drug.Name + "\n" +
                                   "generic name: " + drug.GenericName + "\n" +
                                   "quantity: " + recept.Quantity + " in day for " + recept.Days;

            receptDetail1 += recept.Days > 1 ? " day." : " days.";
            string receptDetail2 = "code: " + drug.IdCode + "\n" +
                                   "valid until: " + recept.ExpirationDate.ToShortDateString();

            //-------------------------------------------

            y += 30;

            gfx.DrawRoundedRectangle(new XPen(XColors.RoyalBlue, Math.PI),
                                     XBrushes.White, 15, y, 250, 100, 20, 20);

            XRect rect = new XRect(25, y + 15, 200, 100);

            // gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString(drName, font, XBrushes.Black, rect, XStringFormats.TopLeft);
            //-------------------------------------------

            gfx.DrawRoundedRectangle(new XPen(XColors.RoyalBlue, Math.PI),
                                     XBrushes.White, page.Width / 3 + 140 - 15, y, 250, 100, 20, 20);

            rect = new XRect(page.Width / 3 + 140, y + 15, 250, 220);
            // gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString(patientDetail, font, XBrushes.Black, rect, XStringFormats.TopLeft);
            //-------------------------------------------


            y += 120;

            gfx.DrawString("Drug: ", new XFont("Times New Roman", 20, XFontStyle.Bold)
                           , XBrushes.Black, new XRect(25, y, 5, 0), XStringFormats.TopLeft);

            gfx.DrawRoundedRectangle(new XPen(XColors.RoyalBlue, Math.PI),
                                     XBrushes.White, 15, y + 30, 560, 80, 20, 20);

            rect = new XRect(25, y + 40, 420, 100);
            // gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString(receptDetail1, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            rect         = new XRect(page.Width / 3 + 140, y + 40, 420, 100);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString(receptDetail2, font, XBrushes.Black, rect, XStringFormats.TopLeft);


            //-------------------------------------------
            string filename = "recept.pdf";

            document.Save(filename);
            Process.Start(filename);
        }
        public static (PdfDocument document, (string crisisType, int startIndex)[]) CreateDocument(IEnumerable <CardData> cards, DateTime fileChanged, int currentInstance)
        {
            var pageWdith  = XUnit.FromInch(2.5);
            var pageHeight = XUnit.FromInch(3.5);


            PdfDocument document = new PdfDocument();

            document.Info.Title    = "Forschungs Karten";
            document.Info.Subject  = "Die Forschungskarten des spiels";
            document.Info.Author   = "Arbeitstitel Karthago";
            document.Info.Keywords = "Karten, Forschung, Karthago";


            //var maxOccurenceOfCard = cards.Max(x => x.Metadata.Times);
            int    counter         = 0;
            var    total           = cards.Sum(x => x.Metadata.Times);
            string currentCardType = null;
            var    resultList      = new List <(string crisisType, int startIndex)>();

            foreach (var card in cards)
            {
                if (card.Metadata.Type != null && currentCardType != null)
                {
                    // Create new Back
                    CrateBack(pageWdith, pageHeight, document, currentCardType);
                }

                if (card.Metadata.Type != null)
                {
                    resultList.Add((card.Metadata.Type, document.PageCount));
                }

                currentCardType = card.Metadata.Type ?? currentCardType;
                if (currentCardType is null)
                {
                    Console.WriteLine($"{currentInstance}: Did not found card metadata. SKIP");
                    continue;
                }
                var header = card.Content.FirstOrDefault(x => x is HeaderBlock);
                Console.WriteLine($"{currentInstance}: Working on <{header?.ToString() ?? "UNKNOWN TITLE"}> with {card.Metadata.Times} instances.");
                for (int i = 0; i < card.Metadata.Times; i++)
                {
                    Console.Write($"{i + 1}...");
                    counter++;

                    PdfPage page = document.AddPage();

                    page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
                    page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


                    XGraphics gfx = XGraphics.FromPdfPage(page);
                    // HACK²
                    gfx.MUH = PdfFontEncoding.Unicode;
                    //gfx.MFEH = PdfFontEmbedding.Default;

                    XFont font = new XFont("Verdana", 13, XFontStyle.Regular);



                    var costSize = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);

                    var costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);



                    var actionRect     = new XRect(costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), pageHeight * 2, costSize.Height * 2);
                    var actionTextRect = actionRect;
                    actionTextRect.Height = costSize.Height;
                    actionTextRect.Offset(new XUnit(3, XGraphicsUnit.Millimeter), 0);

                    gfx.TranslateTransform(new XUnit(3, XGraphicsUnit.Millimeter), 0);
                    gfx.RotateAtTransform(90, actionRect.TopLeft);



                    gfx.DrawRoundedRectangle(XPens.MidnightBlue, XBrushes.DarkSlateBlue, actionRect, new XSize(10, 10));
                    gfx.DrawString(currentCardType, font, XBrushes.White,
                                   actionTextRect, XStringFormats.CenterLeft);

                    gfx.RotateAtTransform(-90, actionRect.TopLeft);
                    gfx.TranslateTransform(new XUnit(-3, XGraphicsUnit.Millimeter), 0);

                    var circle = new XRect(new XUnit(-3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(10, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter));

                    gfx.DrawEllipse(XPens.MidnightBlue, XBrushes.White, circle);

                    gfx.DrawString($"{card.Metadata.Duration:n0}", font, XBrushes.Black,
                                   circle, XStringFormats.Center);


                    var dateRec  = new XRect(new XUnit(13, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter));
                    var dateFont = new XFont("Verdana", 7, XFontStyle.Regular);
                    gfx.DrawString(fileChanged.ToString(), dateFont, XBrushes.Gray, dateRec.TopLeft);
                    gfx.DrawString($"{counter}/{total}", dateFont, XBrushes.Gray, new XRect(0, 0, pageWdith - new XUnit(3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter)), XStringFormats.BottomRight);

                    // Create a new MigraDoc document
                    var doc = new Document();
                    doc.Info.Title   = "Krisen Karten";
                    doc.Info.Subject = "Die Krisenkarten des spiels";
                    doc.Info.Author  = "Arbeitstitel Karthago";


                    doc.DefaultPageSetup.PageWidth  = new Unit(pageWdith.Inch, UnitType.Inch);
                    doc.DefaultPageSetup.PageHeight = new Unit(pageHeight.Inch, UnitType.Inch);

                    doc.DefaultPageSetup.LeftMargin   = new Unit(13, UnitType.Millimeter);
                    doc.DefaultPageSetup.RightMargin  = new Unit(5, UnitType.Millimeter);
                    doc.DefaultPageSetup.BottomMargin = new Unit(10, UnitType.Millimeter);
                    doc.DefaultPageSetup.TopMargin    = new Unit(6, UnitType.Millimeter);

                    doc.DefineStyles();

                    //Cover.DefineCover(document);
                    //DefineTableOfContents(document);

                    DefineContentSection(doc);
                    card.Content.HandleBlocks(doc);


                    // Create a renderer and prepare (=layout) the document
                    MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
                    docRenderer.PrepareDocument();

                    //XRect rect = new XRect(new XPoint(Unit.FromCentimeter(1).Value, Unit.FromCentimeter(3).Value), new XSize((pageWdith.Value - Unit.FromCentimeter(2).Value), (pageHeight.Value - Unit.FromCentimeter(4).Value)));

                    // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
                    //XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);

                    // Draw page border for better visual representation
                    //gfx.DrawRectangle(XPens.LightGray, A4Rect);

                    // Render the page. Note that page numbers start with 1.
                    docRenderer.RenderPage(gfx, 1);

                    // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.

                    // Pop the previous graphical state
                    //gfx.EndContainer(container);
                }
                Console.WriteLine(" Finished card.");
            }
            CrateBack(pageWdith, pageHeight, document, currentCardType);


            //DefineParagraphs(document);
            //DefineTables(document);
            //DefineCharts(document);

            return(document, resultList.ToArray());
        }
Esempio n. 25
0
        public static PdfDocument Create(Profile profile)
        {
            PdfDocument document = new PdfDocument();

            document.Info.Title = "Hotkey map for Desktop Manager";
            PdfPage page = document.AddPage();

            page.Orientation = PageOrientation.Landscape;
            XGraphics gfx = XGraphics.FromPdfPage(page);

            int l = 46;
            int t = 48;
            int w = 750;
            int h = 500;

            foreach (var display in profile.Displays)
            {
                gfx.DrawRectangle(new XPen(XColor.FromArgb(0, 0, 0), .5f), ResizedF(
                                      display.Bounds.Rectangle(), profile.TotalArea.Rectangle(), new Rectangle(l, t, w, h)));
            }

            foreach (var zone in profile.Zones)
            {
                var resizedF = ResizedF(zone.Area.Rectangle(), profile.TotalArea.Rectangle(), new Rectangle(l, t, w, h));
                gfx.DrawRectangle(new XSolidBrush(Color.White), resizedF);
                gfx.DrawRectangle(new XPen(XColor.FromArgb(0, 0, 0), .5f), resizedF);
                if (!zone.Hotkey.Empty)
                {
                    int   insideBorder = 2;
                    int   inbetween    = 1;
                    var   ellipseSize  = new XSize(2, 2);
                    XFont f            = new XFont("Segoe UI", Settings.PdFTextSize);

                    double totalLength1 = 0;
                    double totalLength2 = gfx.MeasureString(zone.Hotkey.KeyCode.ToString(), f).Width + (2 * insideBorder);
                    double hg           = gfx.MeasureString("AltCtrlShift" + zone.Hotkey.KeyCode.ToString(), f).Height + (2 * insideBorder);
                    if (zone.Hotkey.Alt)
                    {
                        totalLength1 += gfx.MeasureString("Alt", f).Width + (2 * insideBorder) + inbetween;
                    }
                    if (zone.Hotkey.Control)
                    {
                        totalLength1 += gfx.MeasureString("Ctrl", f).Width + (2 * insideBorder) + inbetween;
                    }
                    if (zone.Hotkey.Shift)
                    {
                        totalLength1 += gfx.MeasureString("Shift", f).Width + (2 * insideBorder) + inbetween;
                    }
                    if (zone.Hotkey.Windows)
                    {
                        totalLength2 += hg + inbetween; // Square key
                    }

                    double start       = resizedF.X + (resizedF.Width / 2) - (Math.Max(totalLength1, totalLength2) / 2);
                    var    borderPen   = new XPen(XColor.FromArgb(80, 80, 80), .5f);
                    var    stringBrush = new XSolidBrush(XColor.FromArgb(80, 80, 80));
                    if (zone.Hotkey.Alt)
                    {
                        gfx.DrawRoundedRectangle(borderPen, new RectangleF(
                                                     (float)start, (float)(resizedF.Top + (resizedF.Height / 2) - hg),
                                                     (float)gfx.MeasureString("Alt", f).Width + (2 * insideBorder), (float)hg), ellipseSize);
                        gfx.DrawString("Alt", f, stringBrush, new PointF(
                                           (float)(start + insideBorder + (gfx.MeasureString("Alt", f).Width / 2) - 1),
                                           (float)(resizedF.Top + ((resizedF.Height - hg) / 2))), XStringFormats.Center);
                        start += gfx.MeasureString("Alt", f).Width + (2 * insideBorder) + inbetween;
                    }
                    if (zone.Hotkey.Control)
                    {
                        gfx.DrawRoundedRectangle(borderPen, new RectangleF(
                                                     (float)start, (float)(resizedF.Top + (resizedF.Height / 2) - hg),
                                                     (float)gfx.MeasureString("Ctrl", f).Width + (2 * insideBorder), (float)hg), ellipseSize);
                        gfx.DrawString("Ctrl", f, stringBrush, new PointF(
                                           (float)(start + insideBorder + (gfx.MeasureString("Ctrl", f).Width / 2) - 1),
                                           (float)(resizedF.Top + ((resizedF.Height - hg) / 2))), XStringFormats.Center);
                        start += gfx.MeasureString("Ctrl", f).Width + (2 * insideBorder) + inbetween;
                    }
                    if (zone.Hotkey.Shift)
                    {
                        gfx.DrawRoundedRectangle(borderPen, new RectangleF(
                                                     (float)start, (float)(resizedF.Top + (resizedF.Height / 2) - hg),
                                                     (float)gfx.MeasureString("Shift", f).Width + (2 * insideBorder), (float)hg), ellipseSize);
                        gfx.DrawString("Shift", f, stringBrush, new PointF(
                                           (float)(start + insideBorder + (gfx.MeasureString("Shift", f).Width / 2) - 1),
                                           (float)(resizedF.Top + ((resizedF.Height - hg) / 2))), XStringFormats.Center);
                    }
                    start = resizedF.X + (resizedF.Width / 2) - (Math.Max(totalLength1, totalLength2) / 2);
                    if (zone.Hotkey.Windows)
                    {
                        var winPen = new XPen(XColor.FromArgb(80, 80, 80), (Settings.PdFTextSize / 8) * .5f);
                        gfx.DrawRoundedRectangle(borderPen, new RectangleF(
                                                     (float)start, (float)(inbetween + resizedF.Top + (resizedF.Height / 2)),
                                                     (float)hg, (float)hg), ellipseSize);
                        var x = new float[, ] {
                            { (float)(start + .4 * hg), (float)(start + .7 * hg), (float)(start + hg) },
                            { (float)(start + .3 * hg), (float)(start + .6 * hg), (float)(start + .9 * hg) },
                            { (float)(start + .2 * hg), (float)(start + .5 * hg), (float)(start + .8 * hg) }
                        };
                        var y = new float[] { (float)(resizedF.Top + (resizedF.Height / 2) + .3 * hg), (float)(resizedF.Top + (resizedF.Height / 2) + .6 * hg), (float)(resizedF.Top + (resizedF.Height / 2) + .9 * hg) };
                        for (int i = 0; i < 3; i++)
                        {
                            gfx.DrawLine(winPen, x[0, i] - 1, y[0], x[2, i] - 1, y[2]);
                            gfx.DrawCurve(winPen, new PointF[] {
                                new PointF(x[i, 0] - 1, y[i]),
                                new PointF((x[i, 0] + x[i, 1]) / 2 - 1, (float)(y[i] - .06 * hg)),
                                new PointF(x[i, 1] - 1, y[i]),
                                new PointF((x[i, 1] + x[i, 2]) / 2 - 1, (float)(y[i] + .06 * hg)),
                                new PointF(x[i, 2] - 1, y[i])
                            });
                        }
                        start += hg + inbetween;
                    }

                    gfx.DrawRoundedRectangle(borderPen, new RectangleF(
                                                 (float)start, (float)(inbetween + resizedF.Top + (resizedF.Height / 2)),
                                                 (float)gfx.MeasureString(zone.Hotkey.KeyCode.ToString(), f).Width + (2 * insideBorder), (float)hg), ellipseSize);
                    gfx.DrawString(zone.Hotkey.KeyCode.ToString(), f, stringBrush, new PointF(
                                       (float)(start + insideBorder + (gfx.MeasureString(zone.Hotkey.KeyCode.ToString(), f).Width / 2) - 1),
                                       (float)(inbetween + resizedF.Top + ((resizedF.Height + hg) / 2))), XStringFormats.Center);
                }
            }

            return(document);
        }
        public static PdfDocument CreateDocument(IEnumerable <CardData> cards, DateTime fileChanged)
        {
            var pageWdith  = XUnit.FromInch(2.5);
            var pageHeight = XUnit.FromInch(3.5);


            PdfDocument document = new PdfDocument();

            document.Info.Title    = "Forschungs Karten";
            document.Info.Subject  = "Die Forschungskarten des spiels";
            document.Info.Author   = "Arbeitstitel Karthago";
            document.Info.Keywords = "Karten, Forschung, Karthago";


            //var maxOccurenceOfCard = cards.Max(x => x.Metadata.Times);
            int counter = 0;
            var total   = cards.Count();

            foreach (var card in cards)
            {
                counter++;

                PdfPage page = document.AddPage();

                page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
                page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


                XGraphics gfx = XGraphics.FromPdfPage(page);
                // HACK²
                gfx.MUH = PdfFontEncoding.Unicode;
                //gfx.MFEH = PdfFontEmbedding.Default;

                XFont font = new XFont("Verdana", 13, XFontStyle.Regular);



                var costSize = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);

                var costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);



                var costRect     = new XRect(pageWdith - costSize.Width - costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), costSize.Width, costSize.Height);
                var actionRect   = new XRect(costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), pageWdith - costMarginRight - costMarginRight, costSize.Height);
                var durationRect = costRect;
                durationRect.Height *= 2.1;

                gfx.DrawRoundedRectangle(XPens.RoyalBlue, XBrushes.LightBlue, actionRect, new XSize(10, 10));
                gfx.DrawRoundedRectangle(XPens.Orange, XBrushes.LightYellow, durationRect, new XSize(10, 10));
                gfx.DrawRoundedRectangle(XPens.Purple, XBrushes.MediumPurple, costRect, new XSize(10, 10));


                var costTextRect = costRect;
                costTextRect.Width -= new XUnit(1, XGraphicsUnit.Millimeter);
                gfx.DrawString($"{card.Metadata.Cost:n0} ¤", font, XBrushes.Black,
                               costTextRect, XStringFormats.CenterRight);

                var subfont = Markdown.GetSubstituteFont("⌛");
                subfont = new XFont(subfont.Name, font.Size);

                var durationTextRect = durationRect;
                durationTextRect.Width -= new XUnit(1, XGraphicsUnit.Millimeter);

                gfx.DrawString($"{card.Metadata.Duration:n0} ⌛", subfont, XBrushes.Black,
                               durationTextRect, XStringFormats.BottomRight);


                var actionTextRect = actionRect;
                actionTextRect.Offset(new XUnit(3, XGraphicsUnit.Millimeter), 0);

                gfx.DrawString($"Forschung", font, XBrushes.Black,
                               actionTextRect, XStringFormats.CenterLeft);



                var dateRec  = new XRect(new XUnit(3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter));
                var dateFont = new XFont("Verdana", 7, XFontStyle.Regular);
                gfx.DrawString(fileChanged.ToString(), dateFont, XBrushes.Gray, dateRec.TopLeft);
                gfx.DrawString($"{counter}/{total}", dateFont, XBrushes.Gray, new XRect(0, 0, pageWdith - new XUnit(3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter)), XStringFormats.BottomRight);

                // Create a new MigraDoc document
                var doc = new Document();
                doc.Info.Title   = "Forschungs Karten";
                doc.Info.Subject = "Die Forschungskarten des spiels";
                doc.Info.Author  = "Arbeitstitel Karthago";


                doc.DefaultPageSetup.PageWidth  = new Unit(pageWdith.Inch, UnitType.Inch);
                doc.DefaultPageSetup.PageHeight = new Unit(pageHeight.Inch, UnitType.Inch);

                doc.DefaultPageSetup.LeftMargin   = new Unit(5, UnitType.Millimeter);
                doc.DefaultPageSetup.RightMargin  = new Unit(5, UnitType.Millimeter);
                doc.DefaultPageSetup.BottomMargin = new Unit(10, UnitType.Millimeter);
                doc.DefaultPageSetup.TopMargin    = new Unit(16, UnitType.Millimeter);

                doc.DefineStyles();

                //Cover.DefineCover(document);
                //DefineTableOfContents(document);

                DefineContentSection(doc);
                card.Content.HandleBlocks(doc);


                // Create a renderer and prepare (=layout) the document
                MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
                docRenderer.PrepareDocument();

                //XRect rect = new XRect(new XPoint(Unit.FromCentimeter(1).Value, Unit.FromCentimeter(3).Value), new XSize((pageWdith.Value - Unit.FromCentimeter(2).Value), (pageHeight.Value - Unit.FromCentimeter(4).Value)));

                // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
                //XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);

                // Draw page border for better visual representation
                //gfx.DrawRectangle(XPens.LightGray, A4Rect);

                // Render the page. Note that page numbers start with 1.
                docRenderer.RenderPage(gfx, 1);

                // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.

                // Pop the previous graphical state
                //gfx.EndContainer(container);
            }

            // Back
            {
                PdfPage page = document.AddPage();

                page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
                page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


                XGraphics gfx = XGraphics.FromPdfPage(page);
                // HACK²
                gfx.MUH = PdfFontEncoding.Unicode;
                //gfx.MFEH = PdfFontEmbedding.Default;

                XFont font = new XFont("Verdana", 30, XFontStyle.Regular);



                var costRect = new XRect(0, 0, page.Width, page.Height);


                gfx.DrawString($"Forschung", font, XBrushes.SkyBlue,
                               costRect, XStringFormats.Center);
            }

            //DefineParagraphs(document);
            //DefineTables(document);
            //DefineCharts(document);

            return(document);
        }
Esempio n. 27
0
        /// <summary>
        /// Renders the content of the page.
        /// </summary>
        public void Render(XGraphics gfx)
        {
            XRect  rect;
            XPen   pen;
            double x = 50, y = 100;
            XFont  fontH1     = new XFont("Times", 18, XFontStyle.Bold);
            XFont  font       = new XFont("Times", 12);
            XFont  fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls         = font.GetHeight(gfx);

            // Draw some text
            gfx.DrawString("Create PDF on the fly with PDFsharp",
                           fontH1, XBrushes.Black, x, x);
            gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
                           "text and images on different targets.", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("The object used for drawing is the XGraphics object.",
                           font, XBrushes.Black, x, y);
            y += 2 * ls;

            // Draw an arc
            pen           = new XPen(XColors.Red, 4);
            pen.DashStyle = XDashStyle.Dash;
            gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

            // Draw a star
            XGraphicsState gs = gfx.Save();

            gfx.TranslateTransform(x + 140, y + 30);
            for (int idx = 0; idx < 360; idx += 10)
            {
                gfx.RotateTransform(10);
                gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
            }
            gfx.Restore(gs);

            // Draw a rounded rectangle
            rect = new XRect(x + 230, y, 100, 60);
            pen  = new XPen(XColors.DarkBlue, 2.5);
            XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue);
            XColor color2 = XColors.Red;
            XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2,
                                                                   XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));

            // Draw a pie
            pen           = new XPen(XColors.DarkOrange, 1.5);
            pen.DashStyle = XDashStyle.Dot;
            gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);

            // Draw some more text
            y += 60 + 2 * ls;
            gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
                           "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
            y += ls * 1.1;
            gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
            x += 10;
            y += ls * 1.1;
            gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw above or beneath of the content of an existing PDF page",
                           font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
            x -= 10;
            y += ls * 1.1;
            gfx.DrawString("You can also import an existing PDF page and use it like " +
                           "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
            y += ls * 1.1 * 2;
            gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " +
                           "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            gfx.DrawString("Below this text is a PDF form that will be visible when " +
                           "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            XGraphicsState state   = gfx.Save();
            XRect          rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2));

            gfx.DrawRectangle(XBrushes.Snow, rcImage);
            gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
            gfx.Restore(state);
        }
Esempio n. 28
0
        public void Shapes()
        {
            string filename = "Shapes.pdf";

            PdfDocument document = new PdfDocument();
            //document.Options.ColorMode = PdfColorMode.Cmyk;

            // Set version to PDF 1.4 (Acrobat 5) because we use transparency.
            //if (document.Version < 14)
            //    document.Version = 14;

            //PdfPage page = document.Pages[0];

            //// Get an XGraphics object for drawing beneath the existing content

            //XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

            LayoutHelper helper = new LayoutHelper(document, XUnit.FromCentimeter(2.5), XUnit.FromCentimeter(29.7 - 2.5));
            XUnit        left   = XUnit.FromCentimeter(2.5);

            helper.CreatePage();

            XGraphics gfx = helper.Gfx;

            XRect  rect;
            XPen   pen;
            double x = 50, y = 100;
            XFont  fontH1     = new XFont("Times", 18, XFontStyle.Bold);
            XFont  font       = new XFont("Times", 12);
            XFont  fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls         = font.GetHeight(); //gfx

            // Draw some text
            gfx.DrawString("Create PDF on the fly with PDFsharp",
                           fontH1, XBrushes.Black, x, x);
            gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
                           "text and images on different targets.", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("The object used for drawing is the XGraphics object.",
                           font, XBrushes.Black, x, y);
            y += 2 * ls;

            // Draw an arc
            pen           = new XPen(XColors.Red, 4);
            pen.DashStyle = XDashStyle.Dash;
            gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

            // Draw a star
            XGraphicsState gs = gfx.Save();

            gfx.TranslateTransform(x + 140, y + 30);
            for (int idx = 0; idx < 360; idx += 10)
            {
                gfx.RotateTransform(10);
                gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
            }
            gfx.Restore(gs);

            // Draw a rounded rectangle
            rect = new XRect(x + 230, y, 100, 60);
            pen  = new XPen(XColors.DarkBlue, 2.5);
            XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue);
            XColor color2 = XColors.Red;
            XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2,
                                                                   XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));

            // Draw a pie
            pen           = new XPen(XColors.DarkOrange, 1.5);
            pen.DashStyle = XDashStyle.Dot;
            gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);

            // Draw some more text
            y += 60 + 2 * ls;
            gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
                           "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
            y += ls * 1.1;
            gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
            x += 10;
            y += ls * 1.1;
            gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw above or beneath of the content of an existing PDF page",
                           font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
            x -= 10;
            y += ls * 1.1;
            gfx.DrawString("You can also import an existing PDF page and use it like " +
                           "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
            y += ls * 1.1 * 2;
            gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " +
                           "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            gfx.DrawString("Below this text is a PDF form that will be visible when " +
                           "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            XGraphicsState state   = gfx.Save();
            XRect          rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2));

            gfx.DrawRectangle(XBrushes.Snow, rcImage);
            //gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
            gfx.Restore(state);

            document.Save(filename);

            LaunchPdf(filename);
        }