Esempio n. 1
0
        /// <summary>
        /// Compute the rectangle in which the elements should be positioned.
        /// </summary>
        /// <returns>
        /// If this panel is in an <see cref="Adornment"/> and is its <see cref="Node.LocationElement"/>,
        /// return the <see cref="Adornment.AdornedElement"/>'s size.
        /// Otherwise return a <c>Rect</c> based on this first child's <c>DesiredSize</c>.
        /// Only the Width and Height of the Rect matter in the calculations performed by
        /// <see cref="MeasureOverride"/> and <see cref="ArrangeOverride"/>.
        /// </returns>
        protected virtual Rect ComputeBorder()
        {
            Adornment ad = Diagram.FindAncestor <Adornment>(this);

            if (ad != null)
            {
                FrameworkElement elt = ad.AdornedElement;
                if (elt != null && this == ad.LocationElement)
                {
                    Size sz = ad.GetEffectiveSize(elt);
                    if (sz.Width > 0 && sz.Height > 0)
                    {
                        return(new Rect(0, 0, sz.Width, sz.Height));
                    }
                }
            }

            PrintManager.PageInfo pinfo = this.DataContext as PrintManager.PageInfo;
            if (pinfo != null)
            {
                return(pinfo.Viewport);
            }

            Size s = this.DesiredSize;

            foreach (UIElement child in this.Children)
            {
                s = child.DesiredSize;
                break;
            }
            return(new Rect(0, 0, s.Width, s.Height));
        }
Esempio n. 2
0
    private UIElement GetPage(int pageNumber) {
      if (this.Diagram == null) return null;
      DiagramPanel panel = this.Diagram.Panel;
      if (panel == null) return null;

      int x = pageNumber % this.EffectiveColumns;
      int y = pageNumber / this.EffectiveColumns;
      Rect b = this.EffectiveBounds;
      Size sz = this.EffectivePageSize;
      Rect viewb = new Rect(b.X + x*sz.Width,
                            b.Y + y*sz.Height,
                            Math.Min(sz.Width, Math.Max(1, b.Width-x*sz.Width)),
                            Math.Min(sz.Height, Math.Max(1, b.Height-y*sz.Height)));

      double sc = this.EffectiveScale;
      Size pixsz = new Size(viewb.Width*sc, viewb.Height*sc);
      DiagramPanel ppanel = panel.GrabPrintingPanel(viewb, sc, this.PartsToPrint);

      Thickness th = this.Margin;
      if (Double.IsNaN(th.Left) || th.Left > pixsz.Width/2) th.Left = Math.Min(50, pixsz.Width/2);
      if (Double.IsNaN(th.Top) || th.Top > pixsz.Height/2) th.Top = Math.Min(50, pixsz.Height/2);

      PrintManager.PageInfo info = new PrintManager.PageInfo() {
        Diagram = this.Diagram,
        Index = pageNumber+1,
        Count = this.PageCount,
        Column = x+1,
        ColumnCount = this.EffectiveColumns,
        Row = y+1,
        RowCount = this.EffectiveRows,
        TotalBounds = this.EffectiveBounds,
        ViewportBounds = viewb,
        Scale = sc,
        Size = this.PageSize,
        Viewport = new Rect(th.Left, th.Top, pixsz.Width, pixsz.Height)
      };

      Canvas root = new Canvas();
      Diagram diagram = this.Diagram;
      if (diagram != null &&
          (this.PageOptions & PrintPageOptions.Background) != 0) {
        root.Background = diagram.Background;
      }

      DataTemplate backtemplate = this.BackgroundTemplate;
      if (backtemplate != null) {
        ContentPresenter back = new ContentPresenter();
        back.Content = info;
        back.ContentTemplate = backtemplate;
        Canvas.SetLeft(back, th.Left);
        Canvas.SetTop(back, th.Top);
        root.Children.Add(back);
      }

      if (diagram != null && diagram.GridVisible && diagram.GridPattern != null &&
          (this.PageOptions & PrintPageOptions.Grid) != 0) {
        GridPattern grid = diagram.GridPattern;
        grid.DoUpdateBackgroundGrid(panel, new Rect(viewb.X, viewb.Y, sz.Width, sz.Height), sc, false);
        grid.Width = viewb.Width;
        grid.Height = viewb.Height;
        Canvas.SetLeft(grid, th.Left);
        Canvas.SetTop(grid, th.Top);
        root.Children.Add(grid);
      }

      // instead of ppanel.UpdateScrollTransform(new Point(viewb.X, viewb.Y), sc, pixsz, false):
      var tg = new System.Windows.Media.TransformGroup();
      tg.Children.Add(new System.Windows.Media.TranslateTransform() { X = -viewb.X, Y = -viewb.Y });
      tg.Children.Add(new System.Windows.Media.ScaleTransform() { ScaleX = sc, ScaleY = sc });
      ppanel.RenderTransform = tg;

      // clip
      foreach (UIElement lay in ppanel.Children) {
        lay.Clip = new System.Windows.Media.RectangleGeometry() { Rect = new Rect(viewb.X, viewb.Y, pixsz.Width/sc, pixsz.Height/sc) };
      }

      Canvas.SetLeft(ppanel, th.Left);
      Canvas.SetTop(ppanel, th.Top);
      root.Children.Add(ppanel);

      DataTemplate foretemplate = this.ForegroundTemplate;
      if (foretemplate != null) {
        ContentPresenter fore = new ContentPresenter();
        fore.Content = info;
        fore.ContentTemplate = foretemplate;
        Canvas.SetLeft(fore, th.Left);
        Canvas.SetTop(fore, th.Top);
        root.Children.Add(fore);
      }

      root.Measure(this.PageSize);
      root.Arrange(new Rect(0, 0, this.PageSize.Width, this.PageSize.Height));
      return root;
    }
Esempio n. 3
0
        private UIElement GetPage(int pageNumber)
        {
            if (this.Diagram == null)
            {
                return(null);
            }
            DiagramPanel panel = this.Diagram.Panel;

            if (panel == null)
            {
                return(null);
            }

            int  x     = pageNumber % this.EffectiveColumns;
            int  y     = pageNumber / this.EffectiveColumns;
            Rect b     = this.EffectiveBounds;
            Size sz    = this.EffectivePageSize;
            Rect viewb = new Rect(b.X + x * sz.Width,
                                  b.Y + y * sz.Height,
                                  Math.Min(sz.Width, Math.Max(1, b.Width - x * sz.Width)),
                                  Math.Min(sz.Height, Math.Max(1, b.Height - y * sz.Height)));

            double       sc     = this.EffectiveScale;
            Size         pixsz  = new Size(viewb.Width * sc, viewb.Height * sc);
            DiagramPanel ppanel = panel.GrabPrintingPanel(viewb, sc, this.PartsToPrint);

            Thickness th = this.Margin;

            if (Double.IsNaN(th.Left) || th.Left > pixsz.Width / 2)
            {
                th.Left = Math.Min(50, pixsz.Width / 2);
            }
            if (Double.IsNaN(th.Top) || th.Top > pixsz.Height / 2)
            {
                th.Top = Math.Min(50, pixsz.Height / 2);
            }

            PrintManager.PageInfo info = new PrintManager.PageInfo()
            {
                Diagram        = this.Diagram,
                Index          = pageNumber + 1,
                Count          = this.PageCount,
                Column         = x + 1,
                ColumnCount    = this.EffectiveColumns,
                Row            = y + 1,
                RowCount       = this.EffectiveRows,
                TotalBounds    = this.EffectiveBounds,
                ViewportBounds = viewb,
                Scale          = sc,
                Size           = this.PageSize,
                Viewport       = new Rect(th.Left, th.Top, pixsz.Width, pixsz.Height)
            };

            Canvas  root    = new Canvas();
            Diagram diagram = this.Diagram;

            if (diagram != null &&
                (this.PageOptions & PrintPageOptions.Background) != 0)
            {
                root.Background = diagram.Background;
            }

            DataTemplate backtemplate = this.BackgroundTemplate;

            if (backtemplate != null)
            {
                ContentPresenter back = new ContentPresenter();
                back.Content         = info;
                back.ContentTemplate = backtemplate;
                Canvas.SetLeft(back, th.Left);
                Canvas.SetTop(back, th.Top);
                root.Children.Add(back);
            }

            if (diagram != null && diagram.GridVisible && diagram.GridPattern != null &&
                (this.PageOptions & PrintPageOptions.Grid) != 0)
            {
                GridPattern grid = diagram.GridPattern;
                grid.DoUpdateBackgroundGrid(panel, new Rect(viewb.X, viewb.Y, sz.Width, sz.Height), sc, false);
                grid.Width  = viewb.Width;
                grid.Height = viewb.Height;
                Canvas.SetLeft(grid, th.Left);
                Canvas.SetTop(grid, th.Top);
                root.Children.Add(grid);
            }

            // instead of ppanel.UpdateScrollTransform(new Point(viewb.X, viewb.Y), sc, pixsz, false):
            var tg = new System.Windows.Media.TransformGroup();

            tg.Children.Add(new System.Windows.Media.TranslateTransform()
            {
                X = -viewb.X, Y = -viewb.Y
            });
            tg.Children.Add(new System.Windows.Media.ScaleTransform()
            {
                ScaleX = sc, ScaleY = sc
            });
            ppanel.RenderTransform = tg;

            // clip
            foreach (UIElement lay in ppanel.Children)
            {
                lay.Clip = new System.Windows.Media.RectangleGeometry()
                {
                    Rect = new Rect(viewb.X, viewb.Y, pixsz.Width / sc, pixsz.Height / sc)
                };
            }

            Canvas.SetLeft(ppanel, th.Left);
            Canvas.SetTop(ppanel, th.Top);
            root.Children.Add(ppanel);

            DataTemplate foretemplate = this.ForegroundTemplate;

            if (foretemplate != null)
            {
                ContentPresenter fore = new ContentPresenter();
                fore.Content         = info;
                fore.ContentTemplate = foretemplate;
                Canvas.SetLeft(fore, th.Left);
                Canvas.SetTop(fore, th.Top);
                root.Children.Add(fore);
            }

            root.Measure(this.PageSize);
            root.Arrange(new Rect(0, 0, this.PageSize.Width, this.PageSize.Height));
            return(root);
        }