Ejemplo n.º 1
0
        public void Paint(GraphPath figure, Graphics g, int time)
        {
            Brush brush1 = null;

            brush1 = BrushManager.GetGDIBrushFromPatten(this.pattern, figure.GetBounds());

            g.FillPath(brush1, figure.GPath);
        }
Ejemplo n.º 2
0
        public void pdoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            this.pageSetting = e.PageSettings;
            GraphPath rt1 = tlVectorControl1.SVGDocument.CurrentElement as GraphPath;

            if (rt1 == null)
            {
                return;
            }
            RectangleF rtf1   = rt1.GetBounds();
            int        width  = (int)Math.Round(rtf1.Width * tlVectorControl1.ScaleRatio, 0);
            int        height = (int)Math.Round(rtf1.Height * tlVectorControl1.ScaleRatio, 0);

            if (width > 7000 || height > 7000)
            {
                MessageBox.Show("超出图片限定大小,请重新选定区域。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //PrinterResolution pr = e.PageSettings.PrinterResolution;
            float     d1     = 0.9f;
            float     d2     = 0.9f;
            int       margin = 40;
            Rectangle rectangle1;

            rectangle1 = e.MarginBounds;
            //rectangle1.Width = (int)Math.Round(rectangle1.Width *d1);
            //rectangle1.Height = (int)Math.Round(rectangle1.Height * d1);
            //rectangle1.Inflate(-margin, -margin);
            Rectangle rectandle2 = e.PageBounds;
            //rectangle1.X = (int)Math.Round(rectangle1.X * d1);
            //rectangle1.Y = (int)Math.Round(rectangle1.Y * d2);
            //rectangle1.Width = (int)Math.Round(rectangle1.Width * d1);
            //rectangle1.Height = (int)Math.Round(rectangle1.Height * d2);
            float   single1  = tlVectorControl1.ScaleRatio;
            Margins margins1 = this.pageSetting.Margins.Clone() as Margins;
            //margins1 = new Margins(margin, margin, margin, margin);
            //margins1.Left = rectangle1.X;
            //margins1.Top = rectangle1.Y;
            //margins1.Right = rectandle2.Width - rectangle1.X - rectangle1.Width;
            //margins1.Bottom = rectandle2.Height - rectangle1.Y - rectangle1.Height;
            //margins1.Left = (int)Math.Round(margins1.Left * d1);
            //margins1.Right = (int)Math.Round(margins1.Right * d1);
            //margins1.Top = (int)Math.Round(margins1.Top * d2);
            //margins1.Bottom = (int)Math.Round(margins1.Bottom * d2);
            float f1 = (float)rectangle1.Width / (float)width;
            float f2 = (float)rectangle1.Height / (float)height;

            float f3 = f1 > f2 ? f2 : f1;
            float f4 = 1;

            //if (f3 > 1) { f4 = f3; f3 = 1; }
            pageScale = single1 * f3;
            Graphics g = e.Graphics;

            RectangleF rtf2 = rtf1;

            rtf2.Offset(margins1.Left, margins1.Top);
            rtf2.Width  -= margins1.Left + margins1.Right;
            rtf2.Height -= margins1.Top + margins1.Bottom;
            if (ShowCenter)
            {
                float f11 = (rectangle1.Width - width * f3);
                float f12 = (rectangle1.Height - height * f3);

                if (f1 > f2)
                {
                    rtf1.X -= f11 / 2 / single1 / f3;
                }
                else
                {
                    rtf1.Y -= f12 / 2 / single1 / f3;
                }
            }
            if (ShowCenter && ShowPolygon)
            {
                float f11 = (rectangle1.Width - width * f3);
                float f12 = (rectangle1.Height - height * f3);

                if (f1 > f2)
                {
                    rectangle1.X += (int)Math.Round(f11 / 2, 0);
                }
                else
                {
                    rectangle1.Y += (int)Math.Round(f12 / 2, 0);
                }
            }
            if (ShowPolygon)
            {
                float f11 = (rectangle1.Width - width * f3);
                float f12 = (rectangle1.Height - height * f3);
                if (f1 > f2)
                {
                    rectangle1.Width -= (int)Math.Round(f11, 0);
                }
                else
                {
                    rectangle1.Height -= (int)Math.Round(f12, 0);
                }
            }
            //偏移页边距
            rtf1.Offset(-margins1.Left / single1 / f3, -margins1.Top / single1 / f3);
            g.SetClip(rectangle1);//剪切区域
            //g.DrawRectangle(Pens.Blue, Rectangle.Ceiling(rtf2));
            g.SmoothingMode = SmoothingMode.HighQuality;

            g.CompositingQuality = CompositingQuality.HighQuality;
            PointF ptf = new PointF((rtf1.X + rtf1.Right) / 2, (rtf1.Y + rtf1.Bottom) / 2);
            Point  pt  = new Point((int)ptf.X, (int)ptf.Y);

            //pt.X = 0;

            g.Clear(Color.White);
            if (ShowMap)
            {
                g.ScaleTransform(f3, f3);
                drawMap(g, width, height, pt);
            }
            Matrix matrix1 = new Matrix();

            matrix1.Scale(tlVectorControl1.ScaleRatio * f3, tlVectorControl1.ScaleRatio * f3);
            //matrix1.Scale(f3, f3);
            matrix1.Translate(-rtf1.X, -rtf1.Y);
            //matrix1.Translate(margins1.Left, margins1.Right);
            g.ResetTransform();
            g.Transform = matrix1;

            RenderTo(g);
            g.ResetClip();

            g.ResetTransform();
            //比例尺
            //drawN(g, rectangle1);
        }