private void MeasureView(UIElement view)
 {
     if (this.panel.Children.Contains(view))
     {
         this.panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
     }
     else if (VisualTreeHelper.GetParent(view) == null)
     {
         StackPanel stackPanel = new StackPanel();
         stackPanel.Children.Add(view);
         if (view is VirtualizedContainerService.VirtualizingContainer)
         {
             ((VirtualizedContainerService.VirtualizingContainer)view).Populate();
         }
         stackPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
         stackPanel.UpdateLayout();
         stackPanel.Children.Remove(view);
         FreeFormPanel.SetChildSize(view, view.DesiredSize);
     }
     else
     {
         Fx.Assert(false, "The view should either be un-rooted or contained in the FreeFormPanel");
     }
 }
    Composite
    (
        Double compositeWidth,
        Double compositeHeight,
        String headerText,
        String footerText,
        System.Drawing.Font headerFooterFont,
        IEnumerable<LegendControlBase> legendControls
    )
    {
        Debug.Assert(compositeWidth > 0);
        Debug.Assert(compositeHeight > 0);
        Debug.Assert(headerFooterFont != null);
        Debug.Assert(legendControls != null);
        AssertValid();

        // Note:
        //
        // Don't try taking a shortcut by using
        // NodeXLControl.CopyGraphToBitmap() to get an image of the graph and
        // then compositing the image with the other elements.  That would work
        // if the caller were creating an image, but if it were creating an XPS
        // document, the graph would no longer be scalable.

        Double dScreenDpi =
            WpfGraphicsUtil.GetScreenDpi(m_oNodeXLControl).Width;

        // The NodeXLControl can't be a child of two logical trees, so
        // disconnect it from its parent after saving the current vertex
        // locations.

        m_oLayoutSaver = new LayoutSaver(m_oNodeXLControl.Graph);

        Debug.Assert(m_oNodeXLControl.Parent is Panel);
        m_oParentPanel = (Panel)m_oNodeXLControl.Parent;
        UIElementCollection oParentChildren = m_oParentPanel.Children;
        m_iChildIndex = oParentChildren.IndexOf(m_oNodeXLControl);
        oParentChildren.Remove(m_oNodeXLControl);

        m_oGraphImageScaler = new GraphImageScaler(m_oNodeXLControl);

        m_oGraphImageCenterer = new NodeXLControl.GraphImageCenterer(
            m_oNodeXLControl);

        // The header and footer are rendered as Label controls.  The legend is
        // rendered as a set of Image controls.

        Label oHeaderLabel, oFooterLabel;
        IEnumerable<Image> oLegendImages;
        Double dHeaderHeight, dTotalLegendHeight, dFooterHeight;

        CreateHeaderOrFooterLabel(headerText, compositeWidth, headerFooterFont,
            out oHeaderLabel, out dHeaderHeight);

        CreateLegendImages(legendControls, compositeWidth, out oLegendImages,
            out dTotalLegendHeight);

        CreateHeaderOrFooterLabel(footerText, compositeWidth, headerFooterFont,
            out oFooterLabel, out dFooterHeight);

        m_oNodeXLControl.Width = compositeWidth;

        m_oNodeXLControl.Height = Math.Max(10,
            compositeHeight - dHeaderHeight - dTotalLegendHeight
            - dFooterHeight);

        // Adjust the control's graph scale so that the graph's vertices and
        // edges will be the same relative size in the composite that they are
        // in the control.

        m_oGraphImageScaler.SetGraphScale(
            (Int32)WpfGraphicsUtil.WpfToPx(compositeWidth, dScreenDpi),
            (Int32)WpfGraphicsUtil.WpfToPx(m_oNodeXLControl.Height, dScreenDpi),
            dScreenDpi);

        // Adjust the NodeXLControl's translate transforms so that the
        // composite will be centered on the same point on the graph that the
        // NodeXLControl is centered on.

        m_oGraphImageCenterer.CenterGraphImage( new Size(compositeWidth,
            m_oNodeXLControl.Height) );

        StackPanel oStackPanel = new StackPanel();
        UIElementCollection oStackPanelChildren = oStackPanel.Children;

        // To avoid a solid black line at the bottom of the header or the top
        // of the footer, which is caused by rounding errors, make the
        // StackPanel background color the same as the header and footer.

        oStackPanel.Background = HeaderFooterBackgroundBrush;

        if (oHeaderLabel != null)
        {
            oStackPanelChildren.Add(oHeaderLabel);
        }

        // Wrap the NodeXLControl in a Grid to clip it.

        m_oGrid = new Grid();
        m_oGrid.Width = m_oNodeXLControl.Width;
        m_oGrid.Height = m_oNodeXLControl.Height;
        m_oGrid.ClipToBounds = true;
        m_oGrid.Children.Add(m_oNodeXLControl);

        oStackPanelChildren.Add(m_oGrid);

        foreach (Image oLegendImage in oLegendImages)
        {
            oStackPanelChildren.Add(oLegendImage);
        }

        if (oFooterLabel != null)
        {
            oStackPanelChildren.Add(oFooterLabel);
        }

        Size oCompositeSize = new Size(compositeWidth, compositeHeight);
        Rect oCompositeRectangle = new Rect(new Point(), oCompositeSize);

        oStackPanel.Measure(oCompositeSize);
        oStackPanel.Arrange(oCompositeRectangle);
        oStackPanel.UpdateLayout();

        return (oStackPanel);
    }
Пример #3
0
        public void MergeImages(string fl)
        {
            Canvas canvas = new Canvas();

            if (zoom == 3)
            {
                canvas.Width = 512 * 6.5;
                canvas.Height = 512 * 3.25;
            }
            else if (zoom == 2)
            {
                canvas.Width = 512 * 3.25;
                canvas.Height = 512 * 1.625;
            }

            canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
            canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));
            int Height = ((int)(canvas.ActualHeight));
            int Width = ((int)(canvas.ActualWidth));

            StackPanel mainPanel = new StackPanel();
            mainPanel.Orientation = Orientation.Vertical;

            for (int j = 0; j < limitY; j++)
            {
                StackPanel ph = new StackPanel();
                ph.Orientation = Orientation.Horizontal;
                for (int k = 0; k < limitX; k++)
                {
                    Image stackImg = new Image();
                    stackImg.Source = FromStream(previousJumpBuffStream[j][k]);
                    ph.Children.Add(stackImg);
                }
                mainPanel.Children.Add(ph);
            }

            mainPanel.UpdateLayout();
            canvas.Children.Add(mainPanel);

            canvas.UpdateLayout();

            RenderTargetBitmap _RenderTargetBitmap = new RenderTargetBitmap((int)Width, (int)Height, 96, 96, PixelFormats.Pbgra32);
            _RenderTargetBitmap.Render(mainPanel);

            ImageSource mergedImages = _RenderTargetBitmap;

            SaveImg(mergedImages, fl);

            Stream s = File.OpenRead(fl);
            buffStream.Add(s);
        }
        private double WrapElement(StackPanel parent, ref StackPanel p, double offset, string text, CaptionElement element, TextAlignment align, bool directionApplied = false)
        {
            if ((text == null) || (text == ""))
            {
                return offset;
            }
            Size effectiveSize = this.GetEffectiveSize();
            TimedTextStyle currentStyle = element.CurrentStyle;
            Size size2 = currentStyle.Extent.ToPixelSize(new Size?(effectiveSize));
            double width = size2.Width;
            double height = size2.Height;
            if ((currentStyle.Direction == Direction.RightToLeft) && !directionApplied)
            {
                text = new string(text.ToCharArray().Reverse<char>().ToArray<char>());
            }
            double num3 = ((currentStyle.FontSize.Unit == LengthUnit.PixelProportional) || (currentStyle.FontSize.Unit == LengthUnit.Cell)) ? effectiveSize.Height : height;
            TextBlock textblock = this.GetStyledTextblock(currentStyle, width, num3, false);
            this.SetContent(textblock, text);
            Border border = new Border {
                Background = GetCachedBrush(currentStyle.BackgroundColor)
            };
            FrameworkElement contentElement = null;
            double num4 = currentStyle.OutlineWidth.ToPixelLength(effectiveSize.Height);
            if (this.CaptionsOverrideSettings == null)
            {
                return offset;
            }
            switch (this.CaptionsOverrideSettings.CharacterEdgeAttribute)
            {
                case CaptionsOverrideCharacterEdges.Default:
                    if (num4 <= 0.0)
                    {
                        contentElement = textblock;
                        break;
                    }
                    contentElement = this.ApplyUniformEdge(currentStyle, width, num3, text, textblock);
                    break;

                case CaptionsOverrideCharacterEdges.NoAttribute:
                    contentElement = textblock;
                    break;

                case CaptionsOverrideCharacterEdges.Raised:
                    contentElement = this.ApplyRaisedEdge(currentStyle, width, num3, text, textblock);
                    break;

                case CaptionsOverrideCharacterEdges.Depressed:
                    contentElement = this.ApplyDepressedEdge(currentStyle, width, num3, text, textblock);
                    break;

                case CaptionsOverrideCharacterEdges.Uniform:
                    contentElement = this.ApplyUniformEdge(currentStyle, width, num3, text, textblock);
                    break;

                case CaptionsOverrideCharacterEdges.DropShadow:
                    contentElement = this.ApplyDropShadowEdge(currentStyle, width, num3, text, textblock);
                    break;
            }
            contentElement.Opacity = (currentStyle.Visibility == Visibility.Visible) ? currentStyle.Opacity : 0.0;
            border.Child = contentElement;
            p.Children.Add(border);
            string str = text;
            string str2 = string.Empty;
            double effectiveWidth = textblock.GetEffectiveWidth();
            if (((offset + effectiveWidth) <= size2.Width) || (currentStyle.WrapOption != TextWrapping.Wrap))
            {
                offset += effectiveWidth;
                return offset;
            }
            if ((text.Length <= 0) || (text.IndexOf(' ') >= 0))
            {
                while ((offset + textblock.GetEffectiveWidth()) > size2.Width)
                {
                    int num7 = str.LastIndexOf(' ');
                    if (num7 < 0)
                    {
                        this.SetAllContent(contentElement, text);
                        return 0.0;
                    }
                    str2 = text.Substring(num7 + 1);
                    str = text.Substring(0, num7);
                    this.SetAllContent(contentElement, str);
                }
                p = this.NewPanel(parent, ref offset, element, align);
                return this.WrapElement(parent, ref p, offset, str2, element, align, true);
            }
            if ((offset != 0.0) && (effectiveWidth < size2.Width))
            {
                p.Children.Remove(border);
                p = this.NewPanel(parent, ref offset, element, align);
                return this.WrapElement(parent, ref p, 0.0, text, element, align, true);
            }
            int length = text.Length - 1;
            str = text.Substring(0, length);
            str2 = text.Substring(length);
            this.SetAllContent(contentElement, str);
            while ((offset + textblock.GetEffectiveWidth()) > size2.Width)
            {
                length--;
                str = text.Substring(0, length);
                str2 = text.Substring(length);
                this.SetAllContent(contentElement, str);
                p.UpdateLayout();
            }
            p = this.NewPanel(parent, ref offset, element, align);
            return this.WrapElement(parent, ref p, offset, str2, element, align, true);
        }
        private double WrapElement(StackPanel parent, ref StackPanel p, double offset, string text, CaptionElement element, TextAlignment align, bool directionApplied = false)
        {
            if (text == null || text == "") return offset;

            var effectiveSize = this.GetEffectiveSize();
            var style = element.CurrentStyle;
            var panelSize = style.Extent.ToPixelSize(effectiveSize);
            double panelWidth = panelSize.Width;
            double panelHeight = panelSize.Height;

            if (style.Direction == Direction.RightToLeft && !directionApplied)
            {
                text = new string(text.ToCharArray().Reverse().ToArray());
            }

            double height = style.FontSize.Unit == LengthUnit.PixelProportional || style.FontSize.Unit == LengthUnit.Cell ? effectiveSize.Height : panelHeight;
            TextBlock textblock = GetStyledTextblock(style, panelWidth, height, false);
            SetContent(textblock, text);

            Border border = new Border();
            border.Background = GetCachedBrush(style.BackgroundColor);
            FrameworkElement contentElement;

            double outlineWidth = style.OutlineWidth.ToPixelLength(effectiveSize.Height);
            if (outlineWidth > 0)
            {
                Grid cnv = new Grid();

                // do outline image up and to left
                TextBlock tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform() { X = -1, Y = -1 };

                // do outline image down and to right
                tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform() { X = 1, Y = 1 };

                // do outline image up and to right
                tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform() { X = 1, Y = -1 };

                // do outline image down and to left
                tb2 = GetStyledTextblock(style, panelWidth, height, true);
                SetContent(tb2, text);
                cnv.Children.Add(tb2);
                tb2.RenderTransform = new TranslateTransform() { X = -1, Y = 1 };

                // add the main text
                cnv.Children.Add(textblock);

                // add the border
                contentElement = cnv;
            }
            else
            {
                contentElement = textblock;
            }

            border.Child = contentElement;
            p.Children.Add(border);

            string head = text;
            string tail = string.Empty;
            double elementWidth = textblock.GetEffectiveWidth();
            if (offset + elementWidth > panelSize.Width && style.WrapOption == TextWrapping.Wrap)
            {
                if (text.Length > 0 && text.IndexOf(' ') < 0)
                {
                    if (offset != 0 && elementWidth < panelSize.Width)
                    {
                        p.Children.Remove(border);
                        p = NewPanel(parent, ref offset, element, align);
                        return WrapElement(parent, ref p, 0, text, element, align, true);
                    }
                    int idx = text.Length - 1;
                    head = text.Substring(0, idx);
                    tail = text.Substring(idx);
                    SetAllContent(contentElement, head);
                    while (offset + textblock.GetEffectiveWidth() > panelSize.Width)
                    {
                        idx--;
                        head = text.Substring(0, idx);
                        tail = text.Substring(idx);
                        SetAllContent(contentElement, head);
                        p.UpdateLayout();
                    }
                    p = NewPanel(parent, ref offset, element, align);
                    return WrapElement(parent, ref p, offset, tail, element, align, true);
                }
                while (offset + textblock.GetEffectiveWidth() > panelSize.Width)
                {
                    int idx = head.LastIndexOf(' ');
                    if (idx < 0)
                    {
                        SetAllContent(contentElement, text);
                        return 0;
                    }
                    else
                    {
                        tail = text.Substring(idx + 1);
                        head = text.Substring(0, idx);
                    }
                    SetAllContent(contentElement, head);
                }
                p = NewPanel(parent, ref offset, element, align);
                return WrapElement(parent, ref p, offset, tail, element, align, true);
            }
            else
            {
                offset += elementWidth;
                return offset;
            }
        }
Пример #6
-1
        private void Print(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                PrintDialog dlg = new PrintDialog();
                configData.IsRedy = false;
                configData.IsError = false;
                var conf = new PrintPluginViewModel(configData);
                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName));

                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
                var PageWidth = (int)capabilities.PageImageableArea.ExtentWidth;
                var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight;

                var panel = new StackPanel
                {
                    Margin = new Thickness(conf.Margin),
                };

                var image = new Image
                {
                    Source = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0),
                    Width = PageWidth ,
                    Height = PageHeight,
                    Stretch = Stretch.Uniform,
                };

               
                panel.Children.Add(image);
                panel.UpdateLayout();
                panel.Measure(new Size(PageWidth, PageHeight));
                panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize));
                panel.UpdateLayout();
                dlg.PrintVisual(panel, item.Name);
                image.Source = null;
                panel.Children.Clear();
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error print file", exception);
                configData.IsError = true;
                configData.Error = exception.Message;
            }

            configData.IsRedy = true;            
        }