Beispiel #1
0
        /// <summary>
        /// 更新当前页面对象
        /// </summary>
        /// <returns>操作是否改变了当前页面对象</returns>
        protected bool UpdateCurrentPage()
        {
            if (_Pages != null)
            {
                MultiPageTransform trans = ( MultiPageTransform )this.myTransform;

                PrintPage cpage = null;
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                    -this.AutoScrollPosition.X,
                    -this.AutoScrollPosition.Y,
                    this.ClientSize.Width,
                    this.ClientSize.Height);

                int MaxHeight = 0;
                foreach (PrintPage page in _Pages)
                {
                    System.Drawing.Rectangle rect2 = System.Drawing.Rectangle.Intersect(
                        page.ClientBounds, rect);
                    if (!rect2.IsEmpty)
                    {
                        if (MaxHeight < rect2.Height)
                        {
                            cpage     = page;
                            MaxHeight = rect2.Height;
                        }
                    }
                }
                if (cpage != myCurrentPage)
                {
                    myCurrentPage = cpage;
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        public SimpleRectangleTransform GetTransformItemByViewPosition(float y)
        {
            MultiPageTransform trans = (MultiPageTransform)this.myTransform;

            foreach (SimpleRectangleTransform item in trans)
            {
                if (item.DescRectF.Top >= y && item.DescRectF.Bottom >= y)
                {
                    return(item);
                }
            }
            return(null);
        }
Beispiel #3
0
        public SimpleRectangleTransform GetTransformItemByViewPosition(float x, float y)
        {
            MultiPageTransform trans = (MultiPageTransform)this.myTransform;

            foreach (SimpleRectangleTransform item in trans)
            {
                if (item.DescRectF.Contains(x, y))
                {
                    return(item);
                }
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// 根据指定坐标的位置获得续打位置
        /// </summary>
        /// <param name="x">X坐标值</param>
        /// <param name="y">Y坐标值</param>
        /// <returns>续打位置</returns>
        protected int GetJumpPrintPosition(int x, int y)
        {
            MultiPageTransform trans = ( MultiPageTransform )this.myTransform;

            if (trans.ContainsSourcePoint(x, y))
            {
                int pos = this.myTransform.TransformPoint(x, y).Y;
                if (pos >= 0)
                {
                    return(pos);
                }
            }
            return(0);
        }
Beispiel #5
0
        //private System.Drawing.Printing.Margins myClientMargins = new System.Drawing.Printing.Margins();

        //private System.Drawing.Size myClientPageSize = System.Drawing.Size.Empty ;

        /// <summary>
        /// 刷新坐标转换信息
        /// </summary>
        protected override void RefreshScaleTransform()
        {
            MultiPageTransform trans = ( MultiPageTransform )this.myTransform;

            intGraphicsUnit = _Pages.GraphicsUnit;
            trans.Rate      = GraphicsUnitConvert.GetRate(
                intGraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);

            //float rate = ( float )( 1.0 / this.ClientToViewXRate );
            //trans.Pages = myPages ;
            //trans.Refresh( rate , this.intPageSpacing );
            System.Drawing.Point sp = this.AutoScrollPosition;
            trans.ClearSourceOffset();
            trans.OffsetSource(sp.X, sp.Y, true);
        }
Beispiel #6
0
//		/// <summary>
//		/// 无效矩形区域
//		/// </summary>
//		protected RectangleCounter myInvalidateRect = new RectangleCounter();
//		/// <summary>
//		/// 无效矩形区域
//		/// </summary>
//		[System.ComponentModel.Browsable(false)]
//		public RectangleCounter InvalidateRect
//		{
//			get{ return myInvalidateRect ;}
//		}
//
//		/// <summary>
//		/// 追加无效区域
//		/// </summary>
//		/// <param name="myRect"></param>
//		public void AddInvalidateRect( System.Drawing.Rectangle myRect)
//		{
//			myInvalidateRect.Add( myRect );
//		}
//		/// <summary>
//		/// 追加无效区域
//		/// </summary>
//		/// <param name="x"></param>
//		/// <param name="y"></param>
//		/// <param name="width"></param>
//		/// <param name="height"></param>
//		public void AddInvalidateRect( int x , int y , int width , int height)
//		{
//			myInvalidateRect.Add( x , y , width , height );
//		}
//
//		/// <summary>
//		/// 更新无效区域
//		/// </summary>
//		public void UpdateInvalidateRect()
//		{
//			if( myInvalidateRect.IsEmpty == false)
//			{
//				this.ViewInvalidate( this.myInvalidateRect.Value );
//				this.myInvalidateRect.Clear();
//			}
//		}
        /// <summary>
        /// 使用视图坐标来声明无效区域,程序准备重新绘制无效文档
        /// </summary>
        /// <param name="ViewBounds">无效区域</param>
        public override void ViewInvalidate(System.Drawing.Rectangle ViewBounds)
        {
            ViewBounds = this.FixViewInvalidateRect(ViewBounds);
            if (!ViewBounds.IsEmpty)
            {
                MultiPageTransform trans = this.myTransform as MultiPageTransform;
                if (trans == null)
                {
                    base.ViewInvalidate(ViewBounds);
                }
                else
                {
                    foreach (SimpleRectangleTransform item in trans)
                    {
                        System.Drawing.Rectangle rect = System.Drawing.Rectangle.Intersect(item.DescRect, ViewBounds);
                        if (!rect.IsEmpty)
                        {
                            rect = item.UnTransformRectangle(rect);
                            this.Invalidate(rect);
                        }
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 绘制续打区域
        /// </summary>
        /// <param name="g">图形绘制对象</param>
        /// <param name="ClipRectangle">剪切矩形</param>
        /// <param name="Position">续打位置</param>
        /// <param name="FillColor">填充色</param>
        protected void DrawJumpPrintArea(
            System.Drawing.Graphics g,
            System.Drawing.Rectangle ClipRectangle,
            JumpPrintInfo Position,
            System.Drawing.Color FillColor)
        {
            if (Position == null || Position.Page == null || Position.Enabled == false)
            {
                return;
            }

            MultiPageTransform trans = ( MultiPageTransform )this.myTransform;

            int pos = -1;

            foreach (SimpleRectangleTransform item in trans)
            {
                if (item.ContentStyle == PageContentPartyStyle.Body &&
                    item.PageObject == Position.Page)
                {
                    pos = item.UnTransformPoint(0, Position.Position + ( int )item.DescRectF.Top).Y;
                }
            }
            if (pos < 0)
            {
                return;
            }
            //int pos = trans.UnTransformY( Position );

            if (pos >= 0)
            {
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                    0,
                    0,
                    this.ClientSize.Width,
                    pos);

                System.Drawing.Rectangle rect2 = ClipRectangle;
                if (ClipRectangle.IsEmpty)
                {
                    rect2 = rect;
                }
                else
                {
                    rect2 = System.Drawing.Rectangle.Intersect(rect, rect2);
                }
                if (!rect2.IsEmpty)
                {
                    g.ResetClip();
                    g.PageUnit = System.Drawing.GraphicsUnit.Pixel;
                    g.ResetTransform();
                    using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(FillColor))
                    {
                        g.FillRectangle(b, rect2);
                    }
                    using (System.Drawing.Pen p =
                               new System.Drawing.Pen(System.Drawing.Color.Blue, 2))
                    {
                        g.DrawLine(
                            p,
                            0,
                            rect.Bottom - 1,
                            this.ClientSize.Width,
                            rect.Bottom - 1);
                    }
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// 根据分页信息更新页面排布
        /// </summary>
        public virtual void UpdatePages()
        {
            if (StackTraceHelper.CheckRecursion())
            {
                // 检查递归
                return;
            }
            float rate = ( float )(1.0 / this.ClientToViewXRate);

            if (this.ViewMode == PageViewMode.Normal)
            {
                this.PagesTransform.Clear();
                this.PagesTransform.ClearSourceOffset();
                SimpleRectangleTransform item = new SimpleRectangleTransform();
                item.PageIndex      = 0;
                item.DescRectF      = new RectangleF(0, 0, this.Pages.GetPageMaxWidth(), this.Pages.Height);
                item.SourceRectF    = new RectangleF(0, 0, item.DescRectF.Width * rate, item.DescRectF.Height * rate);
                item.PageObject     = this.Pages[0];
                item.ContentStyle   = PageContentPartyStyle.Body;
                item.Enable         = true;
                item.DocumentObject = this.Pages[0].Document;
                this.PagesTransform.Add(item);
                this.PagesTransform.ClearSourceOffset();
                this.RefreshScaleTransform();
                Size msize = new Size(
                    ( int )Math.Ceiling(item.SourceRectF.Width),
                    ( int )Math.Ceiling(item.SourceRectF.Height));
                if (this.AutoScrollMinSize.Equals(msize) == false)
                {
                    this.AutoScrollMinSize = msize;
                }
                this.CurrentPage = this.Pages[0];
                int topCount = 0;
                foreach (PrintPage page in this.Pages)
                {
                    page.ClientBounds = new Rectangle(
                        0,
                        (int )(topCount * rate),
                        (int)(page.Bounds.Width * rate),
                        (int)(page.Bounds.Height * rate));
                    topCount = topCount + page.Bounds.Height;
                }
                //int ClientWidth = this.ClientSize.Width;
                //int x = 0;
                //if (ClientWidth <= this.AutoScrollMinSize.Width)
                //{
                //    x = 0;// this.PageSpacing / 2;
                //}
                //else
                //{
                //    x = (ClientWidth - this.AutoScrollMinSize.Width) / 2;
                //}

                //this.PagesTransform.OffsetSource(x, 0, false);
            }
            else
            {
                Size TotalSize = new Size(0, 0);

                foreach (PrintPage page in this.Pages)
                {
                    TotalSize.Height = (int)(TotalSize.Height
                                             + this.PageSpacing
                                             + page.PageSettings.ViewPaperHeight * rate);
                    if (TotalSize.Width < page.PageSettings.ViewPaperWidth * rate)
                    {
                        TotalSize.Width = (int)(page.PageSettings.ViewPaperWidth * rate);
                    }
                    //page.OwnerPages = this.Pages;
                }
                TotalSize.Width  += this.PageSpacing * 2;
                TotalSize.Height += this.PageSpacing;
                foreach (PrintPage page in this.Pages)
                {
                    page.ClientLeftFix = (int)(TotalSize.Width
                                               - page.PageSettings.ViewPaperWidth * rate) / 2;
                }
                if (this.AutoScrollMinSize.Equals(TotalSize) == false)
                {
                    this.AutoScrollMinSize = TotalSize;
                }

                MultiPageTransform trans = (MultiPageTransform)this.Transform;
                base.intGraphicsUnit = this.Pages.GraphicsUnit;

                trans.Pages = this.Pages;
                trans.Refresh(rate, this.PageSpacing);

                int ClientWidth = this.ClientSize.Width;
                int x           = 0;
                if (ClientWidth <= TotalSize.Width)
                {
                    x = 0;// this.PageSpacing / 2;
                }
                else
                {
                    x = (ClientWidth - TotalSize.Width) / 2;
                }

                trans.OffsetSource(x, 0, false);

                this.RefreshScaleTransform();

                //System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty ;

                int topCount = this.PageSpacing;
                foreach (PrintPage page in this.Pages)
                {
                    System.Drawing.Rectangle clientRect = System.Drawing.Rectangle.Empty;
                    clientRect.X      = x + page.ClientLeftFix;
                    clientRect.Y      = topCount;
                    clientRect.Width  = (int)(page.PageSettings.ViewPaperWidth * rate);
                    clientRect.Height = (int)(page.PageSettings.ViewPaperHeight * rate);
                    //page.ClientLocation = new Point(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
                    page.ClientBounds  = clientRect;
                    page.ClientMargins = new System.Drawing.Printing.Margins(
                        (int)(page.ViewLeftMargin * rate),
                        (int)(page.ViewRightMargin * rate),
                        (int)(page.ViewTopMargin * rate),
                        (int)(page.ViewBottomMargin * rate));
                    topCount = topCount + clientRect.Height + this.PageSpacing;
                }//foreach

                this.UpdateCurrentPage();
            }
        }
Beispiel #9
0
        /// <summary>
        /// 已重载:绘制文档内容
        /// </summary>
        /// <param name="e">绘制事件参数</param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            //if (this.DesignMode)
            {
                base.OnPaint(e);
            }
            if (this.IsUpdating)
            {
                return;
            }

            System.Drawing.Rectangle clipRect = e.ClipRectangle;
            clipRect.Height += 1;
            System.Drawing.Point sp = this.AutoScrollPosition;
            //int ax = - this.AutoScrollPosition.X ;
            //int ay = - this.AutoScrollPosition.Y ;
            this.RefreshScaleTransform();
            if (this.PagesTransform == null || this.PagesTransform.Count == 0)
            {
                // 没有任何内容可以绘制
                return;
            }
            if (this.ViewMode == PageViewMode.Normal)
            {
                using (SolidBrush b = new SolidBrush(this.PageBackColor))
                {
                    e.Graphics.FillRectangle(b, e.ClipRectangle);
                }
                SimpleRectangleTransform item = this.PagesTransform[0];
                PrintPage myPage = (PrintPage)item.PageObject;

                Rectangle rect = item.SourceRect;
                rect.Width = rect.Width + 30;
                rect       = Rectangle.Intersect(
                    clipRect,
                    rect);

                if (rect.IsEmpty == false)
                {
                    // 保存状态
                    System.Drawing.Drawing2D.GraphicsState state2 = e.Graphics.Save();

                    //try
                    {
                        PaintEventArgs e2 = this.CreatePaintEventArgs(e, item);
                        if (e2 != null)
                        {
                            PageDocumentPaintEventArgs e3 = new PageDocumentPaintEventArgs(
                                e2.Graphics,
                                e2.ClipRectangle,
                                myPage.Document,
                                myPage,
                                item.ContentStyle);
                            e3.ContentBounds = item.DescRect;
                            e3.RenderMode    = ContentRenderMode.Paint;
                            e3.PageIndex     = myPage.PageIndex;
                            e3.NumberOfPages = this.Pages.Count;
                            //e3.EditMode = this.EditMode;
                            if (myPage.Document != null)
                            {
                                myPage.Document.DrawContent(e3);
                            }//if
                        }
                    }
                    //catch (Exception ext)
                    //{
                    //    System.Console.WriteLine(ext.ToString());
                    //}
                    // 恢复状态
                    e.Graphics.Restore(state2);
                }
                return;
            }
//
            MultiPageTransform trans = ( MultiPageTransform )this.Transform;

//			trans.ClearSourceOffset();
//			trans.OffsetSource( sp.X , sp.Y , true );

            System.Drawing.Graphics g = e.Graphics;
            //System.Drawing.Drawing2D.GraphicsState stateBack = e.Graphics.Save();
            foreach (PrintPage myPage in this.Pages)
            {
                System.Drawing.Rectangle ClientBounds = myPage.ClientBounds;
                ClientBounds.Offset(sp);
                ClientBounds.Width = ClientBounds.Width + 20;
                //if( clipRect.Top <= ClientBounds.Bottom  + 5
                //    && clipRect.Bottom >= ClientBounds.Top )
                if (clipRect.IntersectsWith(
                        new Rectangle(
                            ClientBounds.Left,
                            ClientBounds.Top,
                            ClientBounds.Width + 5,
                            ClientBounds.Height + 5)))
                {
                    //this.SetPageIndex( myPage.Index );

                    //e.Graphics.Restore(stateBack);
                    //e.Graphics.ResetClip();
                    DrawPageFrame(
                        myPage,
                        e.Graphics,
                        clipRect,
                        true);

                    for (int iCount = trans.Count - 1; iCount >= 0; iCount--)
                    {
                        SimpleRectangleTransform item = trans[iCount];
                        if (item.Visible && item.PageObject == myPage)
                        {
                            // 显示页眉页脚标记文本
                            if (item.ContentStyle == PageContentPartyStyle.Header)
                            {
                                if (this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.Header ||
                                    this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.HeaderFooter)
                                {
                                    // 绘制页眉标记
                                    //e.Graphics.Restore(stateBack);
                                    DrawHeaderFooterFlag(
                                        PrintingResources.Header,
                                        item.PartialAreaSourceBounds,
                                        e.Graphics);
                                }
                            }
                            else if (item.ContentStyle == PageContentPartyStyle.Footer)
                            {
                                if (this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.Footer ||
                                    this.HeaderFooterFlagVisible == HeaderFooterFlagVisible.HeaderFooter)
                                {
                                    // 绘制页脚标记
                                    //e.Graphics.Restore(stateBack);
                                    DrawHeaderFooterFlag(
                                        PrintingResources.Footer,
                                        item.PartialAreaSourceBounds,
                                        e.Graphics);
                                }
                            }
                            Rectangle rect = item.SourceRect;

                            rect = Rectangle.Intersect(
                                clipRect,
                                rect);

                            if (rect.IsEmpty == false)
                            {
                                System.Drawing.Drawing2D.GraphicsState state2 = e.Graphics.Save();

                                PaintEventArgs e2 = this.CreatePaintEventArgs(e, item);
                                if (e2 != null)
                                {
                                    PageDocumentPaintEventArgs e3 = new PageDocumentPaintEventArgs(
                                        e2.Graphics,
                                        e2.ClipRectangle,
                                        myPage.Document,
                                        myPage,
                                        item.ContentStyle);
                                    e3.ContentBounds = item.DescRect;
                                    e3.RenderMode    = ContentRenderMode.Paint;
                                    e3.PageIndex     = myPage.PageIndex;
                                    e3.NumberOfPages = this.Pages.Count;
                                    //e3.EditMode = this.EditMode;
                                    if (myPage.Document != null)
                                    {
                                        myPage.Document.DrawContent(e3);
                                    }//if
                                }

                                e.Graphics.Restore(state2);

                                if (item.Enable == false)
                                {
                                    // 若区域无效则用白色半透明进行覆盖,以作标记
                                    using (System.Drawing.SolidBrush maskBrush
                                               = new SolidBrush(Color.FromArgb(140, this.PageBackColor)))
                                    {
                                        e.Graphics.FillRectangle(
                                            maskBrush,
                                            rect.Left,
                                            rect.Top,
                                            rect.Width + 2,
                                            rect.Height + 2);
                                    }
                                }
                            }                            //if
                            // ClipRect.Height -= 1;
                        }
                    }    //foreach
                }        //if
            }            //foreach
            DrawHeadShadow();
            //base.OnPaint( e );
            //e.Graphics.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
            //System.Threading.Thread.Sleep(100);
        }