Exemplo n.º 1
0
        public void SetPaintFormat(WidgetViewModelDate wdg)
        {
            _Format.BackColor = wdg.vBackgroundColor;

            _Format.BorderColor = wdg.vBorderLineColor;

            _Format.LineWidth = wdg.vBorderLinethinck;

            _Format.Linestyle = wdg.vBorderlineStyle;

            if (wdg.WidgetType == WidgetType.Shape)//shape widget use format string
            {
                SetFontStyle(wdg);
            }
            else
            {
                _Format.Fontfamily = wdg.vFontFamily;

                _Format.FontSize = wdg.vFontSize;

                _Format.Fontcolor = wdg.vFontColor;

                _Format.IsBold = wdg.vFontBold;

                _Format.IsItalic = wdg.vFontItalic;

                _Format.IsUnderline = wdg.vFontUnderLine;

                _Format.IsStrikeThough = wdg.vFontStrickeThrough;
            }
        }
Exemplo n.º 2
0
        private void SetFontStyle(WidgetViewModelDate wdg)
        {
            FormatTextCoverter coverter = new FormatTextCoverter(wdg.vTextContent);

            _Format.Fontfamily = coverter.GetFontFamily();

            _Format.FontSize = coverter.GetFontsize();

            _Format.Fontcolor = coverter.GetFontColor();

            _Format.IsUnderline = coverter.GetFontUnderline();

            _Format.IsStrikeThough = coverter.GetFontStrikeThough();

            _Format.IsItalic = coverter.GetFontItalic();

            _Format.IsBold = coverter.GetFontBold();
        }
        public void AddPreviewWidgets(IEnumerable <BaseWidgetItem> widgets, Canvas parent)
        {
            //Get real left and top property of bound box
            double maxRight  = double.MinValue;
            double maxBottom = double.MinValue;

            if (widgets.Count() <= 0)
            {
                return;
            }
            foreach (BaseWidgetItem element in widgets)
            {
                WidgetViewModelDate vm = element.DataContext as WidgetViewModelDate;

                Rect rec = new Rect(vm.Raw_Left, vm.Raw_Top, vm.Raw_ItemWidth, vm.Raw_ItemHeight);

                if (vm.RotateAngle != 0)
                {
                    rec = new Rect(0, 0, vm.Raw_ItemWidth, vm.Raw_ItemHeight);

                    rec = element.TransformToAncestor(parent).TransformBounds(rec);
                }
                minleft   = Math.Min(minleft, rec.Left);
                mintop    = Math.Min(mintop, rec.Top);
                maxRight  = Math.Max(maxRight, rec.Left + rec.Width);
                maxBottom = Math.Max(maxBottom, rec.Top + rec.Height);
            }

            try
            {
                Canvas.SetLeft(this, minleft);
                Canvas.SetTop(this, mintop);
                this.Width  = maxRight - minleft;
                this.Height = maxBottom - mintop;
            }
            catch (Exception)
            {
                NLogger.Warn("Preview Canvas Width and Height must be non-negative:"
                             + minleft + "," + mintop + "," + maxRight + "," + maxBottom);
                this.Width  = 300;
                this.Height = 300;
            }



            //Set real left and top property of preview widget
            foreach (BaseWidgetItem element in widgets)
            {
                WidgetViewModelDate vm = element.DataContext as WidgetViewModelDate;

                Rect rec = new Rect(vm.Left, vm.Top, element.ActualWidth, element.ActualHeight);

                if (vm.RotateAngle != 0)
                {
                    rec = new Rect(0, 0, element.ActualWidth, element.ActualHeight);
                    rec = element.TransformToAncestor(parent).TransformBounds(rec);
                }
                double left = rec.Left - minleft;
                double top  = rec.Top - mintop;

                VisualBrush visualBrush = new VisualBrush();
                visualBrush.AutoLayoutContent = true;

                visualBrush.Visual     = element.Parent as Visual;
                visualBrush.Stretch    = Stretch.None;
                element.ClipToBounds   = true;
                visualBrush.AlignmentX = 0;
                visualBrush.AlignmentY = 0;

                Rectangle rectangle = new Rectangle();

                try
                {
                    rectangle.Height = rec.Height;
                    rectangle.Width  = rec.Width;
                    rectangle.Fill   = visualBrush;
                }
                catch
                {
                    NLogger.Warn("Widget Rectabgke Width and Height must be non-negative.");
                    continue;
                }

                AdornerMovePreviewCanvas.Children.Add(rectangle);
                Canvas.SetLeft(rectangle, left);
                Canvas.SetTop(rectangle, top);
            }
            AdornerMovePreviewCanvas.InvalidateVisual();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create thumbNail for custom widget.
        /// </summary>
        /// <param name="bAllWidget">true: all widgets in the page, false: selected widgets in the page</param>
        /// <returns>ThumbNail icon</returns>
        private Stream CreateIconImage(bool bAllWidget)
        {
            if (this.EditorCanvas == null)
            {
                return(null);
            }

            //Get real height and width property of image bound box
            double         minleft   = double.MaxValue;
            double         mintop    = double.MaxValue;
            double         maxRight  = double.MinValue;
            double         maxBottom = double.MinValue;
            DesignerCanvas DeCanvas  = _editorCanvas as DesignerCanvas;

            IEnumerable <BaseWidgetItem> widgets;

            if (bAllWidget)
            {
                if (DeCanvas.AllWidgetItems.Count() <= 0)
                {
                    return(null);
                }

                widgets = DeCanvas.AllWidgetItems.OrderBy(i => (i.DataContext as WidgetViewModelDate).ZOrder);
            }
            else
            {
                if (DeCanvas.SelectedItemAndChildren.Count() <= 0)
                {
                    return(null);
                }

                widgets = DeCanvas.SelectedItemAndChildren.OrderBy(i => (i.DataContext as WidgetViewModelDate).ZOrder);
            }


            foreach (BaseWidgetItem element in widgets)
            {
                WidgetViewModelDate vm = element.DataContext as WidgetViewModelDate;
                Rect rec = new Rect(vm.Left, vm.Top, element.ActualWidth, element.ActualHeight);
                if (vm.RotateAngle != 0)
                {
                    //Point offset = element.TransformToAncestor(parent).Transform(new Point(0, 0));
                    rec = new Rect(0, 0, element.ActualWidth, element.ActualHeight);
                    rec = element.TransformToAncestor(DeCanvas).TransformBounds(rec);
                }
                minleft   = Math.Min(minleft, rec.Left);
                mintop    = Math.Min(mintop, rec.Top);
                maxRight  = Math.Max(maxRight, rec.Left + rec.Width);
                maxBottom = Math.Max(maxBottom, rec.Top + rec.Height);
            }
            double nBoundWdith  = maxRight - minleft;
            double nBoundHeight = maxBottom - mintop;

            //map all widget into a DrawingVisual, make output image ready
            DrawingVisual  tDrawingVisual = new DrawingVisual();
            ScaleTransform stf            = new ScaleTransform();
            double         scale;

            if (nBoundWdith > nBoundHeight)
            {
                scale = 74d / nBoundWdith;
            }
            else
            {
                scale = 74d / nBoundHeight;
            }
            stf.ScaleX = Math.Min(1d, scale);
            stf.ScaleY = Math.Min(1d, scale);
            tDrawingVisual.Transform = stf;
            using (DrawingContext context = tDrawingVisual.RenderOpen())
            {
                foreach (BaseWidgetItem element in widgets)
                {
                    VisualBrush tVisualBrush = new VisualBrush(element);
                    tVisualBrush.Stretch    = Stretch.Fill;
                    tVisualBrush.AlignmentX = 0;
                    tVisualBrush.AlignmentY = 0;

                    WidgetViewModelDate vm = element.DataContext as WidgetViewModelDate;
                    double x = vm.Left - minleft;
                    double y = vm.Top - mintop;

                    Rect rec = new Rect(x, y, element.ActualWidth, element.ActualHeight);
                    if (vm.RotateAngle != 0)
                    {
                        //Point offset = element.TransformToAncestor(parent).Transform(new Point(0, 0));
                        rec   = new Rect(0, 0, element.ActualWidth, element.ActualHeight);
                        rec   = element.TransformToAncestor(DeCanvas).TransformBounds(rec);
                        rec.X = rec.X - minleft;
                        rec.Y = rec.Y - mintop;
                    }

                    context.DrawRectangle(tVisualBrush, null, rec);
                }
                context.Close();
            }
            RenderTargetBitmap bmp = new RenderTargetBitmap((int)(nBoundWdith * scale), (int)(nBoundHeight * scale), 96, 96, PixelFormats.Pbgra32);

            bmp.Render(tDrawingVisual);


            //Output the image stream.
            BitmapEncoder encoder;

            encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bmp));

            MemoryStream stream = new MemoryStream();

            encoder.Save(stream);
            return(stream);
        }
Exemplo n.º 5
0
        private Stream CreateThumbNailImage()
        {
            if (this.EditorCanvas == null)
            {
                return(null);
            }
            try
            {
                //Get real height and width property of image bound box
                //double minleft = double.MaxValue;
                //double mintop = double.MaxValue;
                double         maxRight  = double.MinValue;
                double         maxBottom = double.MinValue;
                DesignerCanvas DeCanvas  = _editorCanvas as DesignerCanvas;
                if (DeCanvas.AllWidgetItems.Count() <= 0)
                {
                    return(null);
                }

                IEnumerable <BaseWidgetItem> SortedWidgets =
                    DeCanvas.AllWidgetItems.OrderBy(i => (i.DataContext as WidgetViewModelDate).ZOrder);
                foreach (BaseWidgetItem element in SortedWidgets)
                {
                    WidgetViewModelDate vm = element.DataContext as WidgetViewModelDate;
                    Rect rec = new Rect(vm.Left, vm.Top, element.ActualWidth, element.ActualHeight);
                    if (vm.RotateAngle != 0)
                    {
                        //Point offset = element.TransformToAncestor(parent).Transform(new Point(0, 0));
                        rec = new Rect(0, 0, element.ActualWidth, element.ActualHeight);
                        rec = element.TransformToAncestor(DeCanvas).TransformBounds(rec);
                    }

                    maxRight  = Math.Max(maxRight, rec.Left + rec.Width);
                    maxBottom = Math.Max(maxBottom, rec.Top + rec.Height);
                }

                maxRight  = maxRight + 10d;
                maxBottom = maxBottom + 10d;
                double scale = 80 / Math.Max(maxRight, maxBottom);
                scale = Math.Min(scale, 1d);
                //scale = 1;
                //map all widget into a DrawingVisual, make output image ready
                DrawingVisual  tDrawingVisual = new DrawingVisual();
                ScaleTransform stf            = new ScaleTransform();


                stf.ScaleX = scale;
                stf.ScaleY = scale;
                tDrawingVisual.Transform = stf;
                using (DrawingContext context = tDrawingVisual.RenderOpen())
                {
                    foreach (BaseWidgetItem element in SortedWidgets)
                    {
                        VisualBrush tVisualBrush = new VisualBrush(element);
                        tVisualBrush.Stretch    = Stretch.Fill;
                        tVisualBrush.AlignmentX = 0;
                        tVisualBrush.AlignmentY = 0;

                        WidgetViewModelDate vm = element.DataContext as WidgetViewModelDate;
                        Rect rec = new Rect(vm.Left, vm.Top, element.ActualWidth, element.ActualHeight);
                        if (vm.RotateAngle != 0)
                        {
                            //Point offset = element.TransformToAncestor(parent).Transform(new Point(0, 0));
                            rec = new Rect(0, 0, element.ActualWidth, element.ActualHeight);
                            rec = element.TransformToAncestor(DeCanvas).TransformBounds(rec);
                        }

                        context.DrawRectangle(tVisualBrush, null, rec);
                    }
                    context.Close();
                }
                RenderTargetBitmap bmp = new RenderTargetBitmap((int)(maxRight * scale), (int)(maxBottom * scale), 96, 96, PixelFormats.Pbgra32);
                bmp.Render(tDrawingVisual);


                //Output the image stream.
                BitmapEncoder encoder;
                encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));

                ////using (Stream stm = File.Create(@"d:\123.png"))
                ////{
                ////    encoder.Save(stm);
                ////}
                ////return;
                MemoryStream stream = new MemoryStream();
                encoder.Save(stream);
                return(stream);
            }
            catch
            {
                return(null);
            }
        }