Exemplo n.º 1
1
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);

            gfx.Restore(state);
        }
Exemplo n.º 2
0
        private static XPoint DrawLineArrowInternal(XGraphics gfx, XPen pen, XSolidBrush brush, double x, double y, double angle, Core2D.Style.ArrowStyle style)
        {
            XPoint pt;
            var    rt = new XMatrix();
            var    c  = new XPoint(x, y);

            rt.RotateAtPrepend(angle, c);
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            switch (style.ArrowType)
            {
            default:
            case Core2D.Style.ArrowType.None:
            {
                pt = new XPoint(x, y);
            }
            break;

            case Core2D.Style.ArrowType.Rectangle:
            {
                pt = rt.Transform(new XPoint(x - sx, y));
                var rect = new XRect(x - sx, y - ry, sx, sy);
                gfx.Save();
                gfx.RotateAtTransform(angle, c);
                DrawRectangleInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                gfx.Restore();
            }
            break;

            case Core2D.Style.ArrowType.Ellipse:
            {
                pt = rt.Transform(new XPoint(x - sx, y));
                gfx.Save();
                gfx.RotateAtTransform(angle, c);
                var rect = new XRect(x - sx, y - ry, sx, sy);
                DrawEllipseInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                gfx.Restore();
            }
            break;

            case Core2D.Style.ArrowType.Arrow:
            {
                pt = rt.Transform(new XPoint(x, y));
                var p11 = rt.Transform(new XPoint(x - sx, y + sy));
                var p21 = rt.Transform(new XPoint(x, y));
                var p12 = rt.Transform(new XPoint(x - sx, y - sy));
                var p22 = rt.Transform(new XPoint(x, y));
                DrawLineInternal(gfx, pen, style.IsStroked, ref p11, ref p21);
                DrawLineInternal(gfx, pen, style.IsStroked, ref p12, ref p22);
            }
            break;
            }

            return(pt);
        }
Exemplo n.º 3
0
        void Box(XGraphics gfx, XRect rect, double startAngle, double sweepAngle)
        {
            double xc = rect.X + rect.Width / 2;
            double yc = rect.Y + rect.Height / 2;
            double a  = startAngle * 0.017453292519943295;
            double b  = (startAngle + sweepAngle) * 0.017453292519943295;

            XGraphicsState state = gfx.Save();

            gfx.IntersectClip(rect);
#if true
#if true_
            for (double deg = 0; deg < 360; deg += 10)
            {
                gfx.DrawLine(XPens.Yellow, xc, yc,
                             (xc + rect.Width / 2 * Math.Cos(deg * 0.017453292519943295)),
                             (yc + rect.Height / 2 * Math.Sin(deg * 0.017453292519943295)));
            }
#endif
            double f = Math.Max(rect.Width / 2, rect.Height / 2);
            for (double deg = 0; deg < 360; deg += 10)
            {
                gfx.DrawLine(XPens.Goldenrod, xc, yc,
                             (xc + f * Math.Cos(deg * 0.017453292519943295)),
                             (yc + f * Math.Sin(deg * 0.017453292519943295)));
            }

            gfx.DrawLine(XPens.PaleGreen, xc, rect.Y, xc, rect.Y + rect.Height);
            gfx.DrawLine(XPens.PaleGreen, rect.X, yc, rect.X + rect.Width, yc);
            //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(a)), (yc + rect.Height / 2 * Math.Sin(a)));
            //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(b)), (yc + rect.Height / 2 * Math.Sin(b)));
#endif
            gfx.Restore(state);
            gfx.DrawRectangle(properties.Pen1.Pen, rect);
        }
Exemplo n.º 4
0
        private static void DrawQrCode(int imageSize, int qrCodeSize, int offsetLeft, int offsetTop, XRect rectangle, Uri uri, string iconPath)
        {
            var icon   = new Bitmap(Image.FromFile(iconPath));
            var bitmap = new QrCode().GenerateImage(uri, icon);
            var ms     = new MemoryStream();

            bitmap.Save(ms, ImageFormat.Bmp);

            var image = XImage.FromStream(ms);

            var state = gfx.Save();

            gfx.RotateAtTransform(-90, new XPoint(rectangle.Left + offsetLeft, rectangle.Top + offsetTop));
            gfx.DrawImage(image, rectangle.Left + offsetLeft, rectangle.Top + offsetTop, qrCodeSize, qrCodeSize);
            gfx.Restore(state);
        }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
0
 protected void PreRender(ref XGraphics gfx, double offsetLeft, double offsetTop, double scaleX, double scaleY)
 {
     gfx.Save();
     gfx.RotateAtTransform(Angle, new XPoint(Util.MillimeterToPoint(offsetLeft + Left + (Width / 2.0)),
                                             Util.MillimeterToPoint(offsetTop + Top + (Height / 2.0))));
     hasExecutedPreRender = true;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Renders the bar code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);

            InitRendering(info);
            info.CurrPosInString = 0;
            //info.CurrPos = info.Center - Size / 2;
            info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);

            if (TurboBit)
            {
                RenderTurboBit(info, true);
            }
            RenderStart(info);
            while (info.CurrPosInString < Text.Length)
            {
                RenderNextPair(info);
            }
            RenderStop(info);
            if (TurboBit)
            {
                RenderTurboBit(info, false);
            }
            if (TextLocation != TextLocation.None)
            {
                RenderText(info);
            }

            gfx.Restore(state);
        }
Exemplo n.º 8
0
    public void DrawBox(XGraphics gfx, XRect rect, XPen borderPen)
    {
        //int dEllipse = 15;
        //XRect rect = new XRect(75, 130, 400, 300);
        //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.DrawRectangle(borderPen, rect);
        //gfx.DrawRoundedRectangle(this.borderPen, new XSolidBrush(this.backColor), rect, new XSize(dEllipse, dEllipse));
        //rect.Inflate(-5, -5);

        //XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
        //gfx.DrawString(title, font, XBrushes.Black, rect, XStringFormat.CenterTop);

        //rect.Inflate(-10, -5);
        //rect.Y += 20;
        //rect.Height -= 20;
        //gfx.DrawRectangle(XPens.Red, rect);

        this._state = gfx.Save();
        gfx.TranslateTransform(rect.X, rect.Y);
        SetBoxX(0);
        SetBoxY(0);
    }
Exemplo n.º 9
0
        public override void SetTransformation(double translateX, double translateY, double rotate, double scaleX, double scaleY)
        {
            // Revert to original state, and immediately put this state on the stack again.
            XGraphics.Restore();
            XGraphics.Save();

            XGraphics.TranslateTransform(translateX, translateY);
            if (rotate != 0.0)
            {
                XGraphics.RotateTransform(rotate / System.Math.PI * 180.0);
            }
            if (scaleX != 1.0 || scaleY != 1.0)
            {
                XGraphics.ScaleTransform(scaleX, scaleY);
            }
        }
Exemplo n.º 10
0
        private byte[] GetDocumentToByteArray(ref Document pdf)
        {
            var renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Automatic)
            {
                Document = pdf
            };

            renderer.RenderDocument();
            var stream = new MemoryStream();

            if (String.IsNullOrWhiteSpace(_getLogoUrl.Get()) &&
                !String.IsNullOrWhiteSpace(_ecommerceSettings.ReportLogoImage))
            {
                XGraphics gfx   = XGraphics.FromPdfPage(renderer.PdfDocument.Pages[0]);
                XImage    image = FromUri(_ecommerceSettings.ReportLogoImage);
                if (image != null)
                {
                    gfx.DrawImage(image, 70, 50, image.PixelWidth, image.PixelHeight);
                    gfx.Save();
                }
            }
            renderer.PdfDocument.Save(stream);

            return(stream.ToArray());
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        public static void DrawBeziers()
        {
            string fn = @"input.pdf";

            using (PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fn))
            {
                // Create an empty XForm object with the specified width and height
                // A form is bound to its target document when it is created. The reason is that the form can
                // share fonts and other objects with its target document.
                using (XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55)))
                {
                    // Create an XGraphics object for drawing the contents of the form.
                    using (XGraphics formGfx = XGraphics.FromForm(form))
                    {
                        // Draw a large transparent rectangle to visualize the area the form occupies
                        XColor back = XColors.Orange;
                        back.A = 0.2;
                        XSolidBrush brush = new XSolidBrush(back);
                        formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);

                        // On a form you can draw...

                        // ... text
                        formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormats.TopLeft);
                        XPen pen = XPens.LightBlue.Clone();
                        pen.Width = 2.5;

                        // ... graphics like Bézier curves
                        formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20 100,140 175,33.3"));

                        // ... raster images like GIF files
                        XGraphicsState state = formGfx.Save();
                        formGfx.RotateAtTransform(17, new XPoint(30, 30));
                        formGfx.DrawImage(XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Test.gif"), 20, 20);
                        formGfx.Restore(state);

                        // ... and forms like XPdfForm objects
                        state = formGfx.Save();
                        formGfx.RotateAtTransform(-8, new XPoint(165, 115));
                        formGfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * System.Math.Sqrt(2)));
                        formGfx.Restore(state);

                        // When you finished drawing on the form, dispose the XGraphic object.
                    } // End Using formGfx
                }     // End Using form
            }         // End Using document
        }
Exemplo n.º 14
0
        public static void PDFExport(string Paydate)
        {
            string InvoiceNumber = "" + SelectedInvoiceNumber + "";

            PdfDocument document = new PdfDocument();

            document.Info.Title   = "Invoice";
            document.Info.Author  = "Jack Huckins";
            document.Info.Subject = "Service Invoice";

            PdfPage page = new PdfPage();

            page        = document.AddPage();
            page.Width  = XUnit.FromInch(8.5);
            page.Height = XUnit.FromInch(11);

            XGraphics gfx = default(XGraphics);

            gfx = XGraphics.FromPdfPage(page);

            XForm form = new XForm(document, XUnit.FromMillimeter(300), XUnit.FromMillimeter(300));

            XGraphics formGfx = default(XGraphics);

            formGfx = XGraphics.FromForm(form);

            XGraphicsState state = default(XGraphicsState);

            state = formGfx.Save();
            //..... Invoice Results
            GetInvResults(Paydate);
            PrepareInvoiceTop(formGfx, state, InvoiceNumber);
            PrepareInvoiceData(6, 217, formGfx);
            PrepareFooter(formGfx);

            state = formGfx.Save();
            formGfx.Dispose();
            gfx.DrawImage(form, 0, 0);
            //document.Save("c:\\Invoices\\Inv " + InvoiceNumber + ".pdf")
            SetReportPath();
            document.Save(ReportPath);
            TimeConnector.Data.ActionLog.Insert("PDF Export", "" + InvoiceNumber + "");
            //UpdatePDFLabel("30 second Check", Form1.lblPDFStatus);
            //var _with1 = ViewPDF;
            //_with1.PdfName = Export.ReportPath;
            //_with1.Show();
        }
Exemplo n.º 15
0
        /// <summary>
        ///   Draw a multi-line string as it would be drawn by GDI+.
        ///   Compensates for issues and draw-vs-PDF differences in PDFsharp.
        /// </summary>
        /// <param name="graphics">The graphics with which to draw.</param>
        /// <param name="font">The font with which to draw.</param>
        /// <param name="brush">The brush with which to draw.</param>
        /// <param name="pos">The position at which to draw.</param>
        /// <param name="size">The size to which to limit the drawn text; or Vector.Zero for no limit.</param>
        /// <param name="format">The string format to use.</param>
        /// <param name="maxObjects"></param>
        /// <param name="text">The text to draw, which may contain line breaks.</param>
        /// <remarks>
        ///   PDFsharp cannot currently render multi-line text to PDF files; it comes out as single line.
        ///   This method simulates standard Graphics.DrawString() over PDFsharp.
        ///   It always has the effect of StringFormatFlags.LineLimit (which PDFsharp does not support).
        /// </remarks>
        public Rect Draw(XGraphics graphics, Font font, Brush brush, Vector pos, Vector size, XStringFormat format)
        {
            // do a quick test to see if text is going to get drawn at the same size as last time;
            // if so, assume we don't need to recompute our layout for that reason.
            var sizeChecker = graphics.MeasureString("M q", font);

            if (sizeChecker != m_sizeChecker || pos != m_pos || m_size != size || m_requestedFormat.Alignment != format.Alignment || m_requestedFormat.LineAlignment != format.LineAlignment || m_requestedFormat.FormatFlags != format.FormatFlags)
            {
                m_invalidLayout = true;
            }
            m_sizeChecker = sizeChecker;

            if (m_invalidLayout)
            {
                // something vital has changed; rebuild our cached layout data
                RebuildCachedLayout(graphics, font, ref pos, ref size, format);
                m_invalidLayout = false;
            }

            var state    = graphics.Save();
            var textRect = new RectangleF(pos.X, pos.Y, size.X, size.Y);

            if (size != Vector.Zero)
            {
                graphics.IntersectClip(textRect);
            }

            // disable smoothing whilst rendering text;
            // visually this is no different, but is faster
            var smoothingMode = graphics.SmoothingMode;

            graphics.SmoothingMode = XSmoothingMode.HighSpeed;

            var origin = m_origin;

            foreach (string t in m_lines)
            {
                if (size.Y > 0 && size.Y < m_lineHeight)
                {
                    break; // not enough remaining vertical space for a whole line
                }
                var line = t;

                graphics.SmoothingMode = XSmoothingMode.HighQuality;


                graphics.DrawString(line, font, brush, origin.X, origin.Y, m_actualFormat);
                origin += m_delta;
                size.Y -= m_lineHeight;
            }

            graphics.SmoothingMode = smoothingMode;
            graphics.Restore(state);

            var actualTextRect = new Rect(pos.X, m_origin.Y, size.X, m_lineHeight * m_lines.Count);

            return(actualTextRect);
        }
Exemplo n.º 16
0
        void DrawSecondHand(XGraphics gfx, XPen pen)
        {
            XGraphicsState gs = gfx.Save();

            gfx.RotateTransform(360 * Time.Second / 60 + 6 * Time.Millisecond / 1000);

            gfx.DrawEllipse(new XSolidBrush(pen.Color), -15, -15, 30, 30);
            gfx.DrawLine(pen, 0, 40, 0, -800);
            gfx.Restore(gs);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Demonstrates the use of XGraphics.SetClip.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            gfx.Save();
            gfx.TranslateTransform(50, 50);
            gfx.IntersectClip(new Rectangle(0, 0, 400, 250));
            gfx.TranslateTransform(50, 50);
            //gfx.Clear(XColor.GhostWhite);
            gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500);
            gfx.Restore();

            gfx.Save();
            //gfx.Transform = new XMatrix();  //XMatrix.Identity;
            gfx.TranslateTransform(200, 200);
            gfx.IntersectClip(new Rectangle(0, 0, 400, 250));
            gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500);
            gfx.Restore();
        }
Exemplo n.º 18
0
        void DrawHourHand(XGraphics gfx, XPen pen, XBrush brush)
        {
            XGraphicsState gs = gfx.Save();

            gfx.RotateTransform(360 * Time.Hour / 12 + 30 * Time.Minute / 60);
            gfx.DrawPolygon(pen, brush,
                            new XPoint[] { new XPoint(0, 150), new XPoint(100, 0),
                                           new XPoint(0, -600), new XPoint(-100, 0) },
                            XFillMode.Winding);
            gfx.Restore(gs);
        }
Exemplo n.º 19
0
        protected void DrawMinuteHand(XGraphics gfx, XPen pen, XBrush brush)
        {
            XGraphicsState gs = gfx.Save();

            gfx.RotateTransform(360 * Time.Minute / 60 + 6 * Time.Second / 60);

            gfx.DrawPolygon(pen, brush,
                            new XPoint[] { new XPoint(0, 200), new XPoint(50, 0), new XPoint(0, -800), new XPoint(-50, 0) },
                            XFillMode.Winding);
            gfx.Restore(gs);
        }
Exemplo n.º 20
0
        private void BeginAddress(XGraphics gfx, int number, string address)
        {
            XRect rect = new XRect(40, 60 + 6 * 60, 104 * 3.5, 16);
            XFont font = new XFont("Verdana", 12, XFontStyle.Regular);

            rect.X += (104 * 3.5 + 20) * (number % 2);
            rect.Y += 17 * (number / 2);

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

            state = gfx.Save();
        }
        /// <summary>
        /// Demonstrates the use of XGraphics.Transform.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            gfx.Save();

            gfx.IntersectClip(new XRect(20, 20, 300, 500));
            gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.IntersectClip(new XRect(100, 200, 300, 500));
            gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


            Matrix matrix = new Matrix();

            //matrix.Scale(2f, 1.5f);
            //matrix.Translate(-200, -400);
            //matrix.Rotate(45);
            //matrix.Translate(200, 400);
            //gfx.Transform = matrix;
            //gfx.TranslateTransform(50, 30);

#if true
            gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
            gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
            gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
            gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
            bool id = matrix.IsIdentity;
            matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
            //matrix.Translate(30, -50);
            matrix.Rotate(15, MatrixOrder.Prepend);
            //Matrix mtx = gfx.Transform.ToGdipMatrix();
            //gfx.Transform = matrix;

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

            //gfx.ResetClip();
            gfx.Restore();

            gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

            gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));
        }
Exemplo n.º 22
0
        public void PdfDraw(XGraphics g)
        {
            XStringFormat formatDec = new XStringFormat();

            formatDec.Alignment     = XStringAlignment.Near;
            formatDec.LineAlignment = XLineAlignment.Center;
            XSolidBrush b = new XSolidBrush(Color.Black);

            for (int i = 0; i < ParentTest.Paper.Blocks.X - 1; i += 7)
            {
                g.DrawEllipse(b, new Rectangle(DesignZone.Left + ((Settings.blockWidth - Settings.blockHeight) / 2) + (i * Settings.blockWidth),
                                               DesignZone.Bottom - 1 - Settings.blockHeight, Settings.blockHeight, Settings.blockHeight));
            }
            for (int i = 0; i < ParentTest.Paper.Blocks.Y - 1; i += 7)
            {
                g.DrawEllipse(b, new Rectangle(DesignZone.Right - 1 - Settings.blockHeight, DesignZone.Top + (i * Settings.blockHeight),
                                               Settings.blockHeight, Settings.blockHeight));
            }
            g.DrawEllipse(b, new Rectangle(DesignZone.Right - 1 - Settings.blockHeight, DesignZone.Bottom - 1 - Settings.blockHeight,
                                           Settings.blockHeight, Settings.blockHeight));

            XGraphicsState gs = g.Save();

            g.RotateAtTransform(90, new XPoint(DesignZone.Right - 1 - (int)(Settings.blockHeight / 2), DesignZone.Top + (2 * Settings.blockHeight)));
            XStringFormat pageNumFormat = new XStringFormat();

            pageNumFormat.LineAlignment = XLineAlignment.Far;

            g.Restore(gs);

            var   barcode = BarCode.CreateArray(Hash());
            Point start   = new Point(DesignZone.Left + (4 * Settings.blockWidth) - 57, DesignZone.Bottom - 25);

            XBrush bGray = new XSolidBrush(XColor.FromArgb(Program.Test.BarCodeGray, Program.Test.BarCodeGray, Program.Test.BarCodeGray));

            for (int i = 0; i < 19; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (barcode[i, j] == 0)
                    {
                        g.DrawRectangle(bGray, start.X + (i * 6), start.Y + (j * 6), 6, 6);
                    }
                }
            }

            foreach (TestElement testElement in TestElements)
            {
                testElement.PdfDraw(g);
            }
        }
Exemplo n.º 23
0
        private void DrawBody(XGraphics gfx)
        {
            for (int x = 0; x < 15; x++)
            {
                XGraphicsState state1 = gfx.Save();
                gfx.RotateAtTransform(-70, new XPoint(200 + (x * 20), 250));
                gfx.DrawString("Long Text Here : Always expect more " + (x + 1), FontUtility.HeaderContentNormal, XBrushes.Black, new XPoint(200 + (x * 20), 250));
                gfx.Restore(state1);
            }

            for (int x = 0; x < 15; x++)
            {
                XPen pen = new XPen(XColors.Gray, 1);
                gfx.DrawRectangle(pen, XBrushes.White, new XRect(195 + (x * 20), 260, 8, 25));
                if (x % 2 == 0)
                {
                    gfx.DrawRectangle(XBrushes.LightGray, new XRect(195 + (x * 20), 270, 8, 15));
                }
            }

            int lineHeight = 20;
            int topHeight  = 0;

            for (int x = 0; x < 20; x++)
            {
                topHeight = 300 + lineHeight * x;
                gfx.DrawLine(XPens.LightGray, 50, topHeight, 490, topHeight);

                if (x % 2 == 0)
                {
                    gfx.DrawString("&", FontUtility.BodyContentTick, XBrushes.Green, new XRect(50, topHeight + 8, 10, 0));
                }
                else
                {
                    gfx.DrawString("#", FontUtility.BodyContentTick, XBrushes.Green, new XRect(50, topHeight + 8, 10, 0));
                }
                gfx.DrawString("Associate Consultant " + (x + 1), FontUtility.BodyContentNormal, XBrushes.Black, new XRect(60, topHeight + 8, 100, 0));
                gfx.DrawString("8/2011 - present", FontUtility.BodyContentNormal, XBrushes.Black, new XRect(50, topHeight + 16, 100, 0));
                for (int y = 0; y < 16; y++)
                {
                    XPen pen = new XPen(XColors.Gray, 1);
                    gfx.DrawLine(pen, new XPoint(190 + (y * 20), topHeight), new XPoint(190 + (y * 20), (topHeight + 20)));
                    if (y % 2 == 0)
                    {
                        gfx.DrawImage(XImage.FromFile("../Images/Green-Tick.png"), new XRect(190 + (y * 20) + 5, topHeight + 6, 10, 10));
                    }
                }
            }
            gfx.DrawLine(XPens.LightGray, 50, topHeight + lineHeight, 490, topHeight + lineHeight);
        }
Exemplo n.º 24
0
        private void Draw8UpPageFor8PageBooklet(XGraphics gfx, int pageNumber, double xorigin, double yorigin)
        {
            var state = gfx.Save();

            _inputPdf.PageNumber = pageNumber;
            var box = new XRect(xorigin, yorigin, _paperWidth / 4, _paperHeight / 2);

            if (yorigin == 0)
            {
                var pagePoint = new XPoint(xorigin + _paperWidth / 8, yorigin + _paperHeight / 4);
                gfx.RotateAtTransform(180, pagePoint);
            }
            gfx.DrawImage(_inputPdf, box);
            gfx.Restore(state);
        }
Exemplo n.º 25
0
        public PdfSharpCanvas(PdfPage page, string fontFamily)
        {
            FontFamily = fontFamily;
            SetupFontMetrics(FontFamily);

            XGraphics = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append, XGraphicsUnit.Millimeter, XPageDirection.Downwards);

            // The origin of an XGraphics canvas is in the top left corner, with the y axis pointing downwards.
            // This transform mirrors the y axis. Unfortunately this also mirrors text output (see workaround in PutText).
            // XGraphics.FromPdfPage can be called with XPageDirection.Upwards, which is marked as obsolete because it is not implemented properly
            // it suffers from the same problem as our matrix below.
            XGraphics.MultiplyTransform(new XMatrix(1.0, 0.0, 0.0, -1.0, 0.0, XGraphics.PageSize.Height));

            // Save the current state so that we can always revert any transformations we apply.
            XGraphics.Save();
        }
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = this.rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO null-Values müssen berücksichtigt werden.
            //     Verbindungspunkte können fehlen, je nachdem wie null-Values behandelt werden sollen.
            //     (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo.matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri.series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri.series.Elements[idx].Value;
                    if (double.IsNaN(v))
                    {
                        v = 0;
                    }
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
            case CodeDirection.RightToLeft:
                gfx.RotateAtTransform(180, position);
                break;

            case CodeDirection.TopToBottom:
                gfx.RotateAtTransform(90, position);
                break;

            case CodeDirection.BottomToTop:
                gfx.RotateAtTransform(-90, position);
                break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
            {
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);
            }

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width  = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
            {
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);
            }

            gfx.Restore(state);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Renders the OMR code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (this.direction)
            {
            case CodeDirection.RightToLeft:
                gfx.RotateAtTransform(180, position);
                break;

            case CodeDirection.TopToBottom:
                gfx.RotateAtTransform(90, position);
                break;

            case CodeDirection.BottomToTop:
                gfx.RotateAtTransform(-90, position);
                break;
            }

            //XPoint pt = center - this.size / 2;
            XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
            uint   value;

            uint.TryParse(this.text, out value);
#if true
            // HACK: Project Wallenwein: set LK
            value |= 1;
            this.synchronizeCode = true;
#endif
            if (this.synchronizeCode)
            {
                XRect rect = new XRect(pt.x, pt.y, this.makerThickness, this.size.height);
                gfx.DrawRectangle(brush, rect);
                pt.x += 2 * this.makerDistance;
            }
            for (int idx = 0; idx < 32; idx++)
            {
                if ((value & 1) == 1)
                {
                    XRect rect = new XRect(pt.x + idx * this.makerDistance, pt.y, this.makerThickness, this.size.height);
                    gfx.DrawRectangle(brush, rect);
                }
                value = value >> 1;
            }
            gfx.Restore(state);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = _rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO Treat null values correctly.
            //     Points can be missing. Treat null values accordingly (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo._matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri._series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri._series.Elements[idx].Value;
                    if (double.IsNaN(v))
                    {
                        v = 0;
                    }
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Renders the OMR code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            //XPoint pt = center - size / 2;
            XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);
            uint value;
            uint.TryParse(Text, out value);
#if true
            // HACK: Project Wallenwein: set LK
            value |= 1;
            _synchronizeCode = true;
#endif
            if (_synchronizeCode)
            {
                XRect rect = new XRect(pt.X, pt.Y, _makerThickness, Size.Height);
                gfx.DrawRectangle(brush, rect);
                pt.X += 2 * _makerDistance;
            }
            for (int idx = 0; idx < 32; idx++)
            {
                if ((value & 1) == 1)
                {
                    XRect rect = new XRect(pt.X + idx * _makerDistance, pt.Y, _makerThickness, Size.Height);
                    gfx.DrawRectangle(brush, rect);
                }
                value = value >> 1;
            }
            gfx.Restore(state);
        }
Exemplo n.º 31
0
    public void DrawBox(XGraphics gfx, XRect rect, XBrush brush)
    {
        gfx.DrawRectangle(brush, rect);
        //gfx.DrawRoundedRectangle(this.borderPen, new XSolidBrush(this.backColor), rect, new XSize(dEllipse, dEllipse));
        //rect.Inflate(-5, -5);

        //XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
        //gfx.DrawString(title, font, XBrushes.Black, rect, XStringFormat.CenterTop);

        //rect.Inflate(-10, -5);
        //rect.Y += 20;
        //rect.Height -= 20;
        //gfx.DrawRectangle(XPens.Red, rect);

        this._state = gfx.Save();
        gfx.TranslateTransform(rect.X, rect.Y);
        SetBoxX(0);
        SetBoxY(0);
    }
Exemplo n.º 32
0
        public static void DrawChevron(XGraphics graphics, PointF pos, float angle, float size, Brush fillBrush)
        {
            if (m_chevronPath == null)
            {
                var apex        = new PointF(0.5f, 0);
                var leftCorner  = new PointF(-0.5f, 0.5f);
                var rightCorner = new PointF(-0.5f, -0.5f);
                m_chevronPath = new XGraphicsPath();
                m_chevronPath.AddLine(apex, rightCorner);
                m_chevronPath.AddLine(rightCorner, leftCorner);
                m_chevronPath.AddLine(leftCorner, apex);
            }
            var state = graphics.Save();

            graphics.TranslateTransform(pos.X, pos.Y);
            graphics.RotateTransform(angle);
            graphics.ScaleTransform(size, size);
            graphics.DrawPath(fillBrush, m_chevronPath);
            graphics.Restore(state);
        }
Exemplo n.º 33
0
    /// <summary>
    /// Renders the bar code.
    /// </summary>
    protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
    {
      XGraphicsState state = gfx.Save();

      BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);
      InitRendering(info);
      info.CurrPosInString = 0;
      //info.CurrPos = info.Center - this.size / 2;
      info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);

      if (TurboBit)
        RenderTurboBit(info, true);
      RenderStart(info);
      while (info.CurrPosInString < this.text.Length)
      {
        RenderNextChar(info);
        RenderGap(info, false);
      }
      RenderStop(info);
      if (TurboBit)
        RenderTurboBit(info, false);
      if (TextLocation != TextLocation.None)
        RenderText(info);

      gfx.Restore(state);
    }
Exemplo n.º 34
0
 /// <summary>
 /// Renders the content found in Text
 /// </summary>
 /// <param name="gfx">
 /// XGraphics - Instance of the drawing surface 
 /// </param>
 /// <param name="brush">
 /// XBrush - Line and Color to draw the bar code 
 /// </param>
 /// <param name="font">
 /// XFont - Font to use to draw the text string 
 /// </param>
 /// <param name="position">
 /// XPoint - Location to render the bar code 
 /// </param>
 protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
     // Create the array to hold the values to be rendered
     this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length];
     String buffer = String.Empty;
     for (Int32 index = 0; index < text.Length; index++)
         switch (this.Code128Code)
         {
             case Code128Type.A:
                 if (text[index] < 32)
                     this.Values[index] = (byte)(text[index] + 64);
                 else if ((text[index] >= 32) && (text[index] < 64))
                     this.Values[index] = (byte)(text[index] - 32);
                 else
                     this.Values[index] = (byte)text[index];
                 break;
             case Code128Type.B:
                 this.Values[index] = (byte)(text[index] - 32);
                 break;
             case Code128Type.C:
                 if ((text[index] >= '0') && (text[index] <= '9'))
                 {
                     buffer += text[index];
                     if (buffer.Length == 2)
                     {
                         this.Values[index / 2] = byte.Parse(buffer);
                         buffer = String.Empty;
                     }
                 }
                 else
                     throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C");
                 break;
         }
     if (this.Values == null)
         throw new InvalidOperationException("Text or Values must be set");
     if (this.Values.Length == 0)
         throw new InvalidOperationException("Text or Values must have content");
     for (int x = 0; x < this.Values.Length; x++)
         if (this.Values[x] > 102)
             throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x));
     XGraphicsState state = gfx.Save();
     BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);
     this.InitRendering(info);
     info.CurrPosInString = 0;
     info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
     this.RenderStart(info);
     foreach (byte c in this.Values)
         this.RenderValue(info, c);
     this.RenderStop(info);
     if (this.TextLocation != TextLocation.None)
         this.RenderText(info);
     gfx.Restore(state);
 }