Ejemplo n.º 1
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            //update
            if (FSVGIn.IsChanged || FSizeIn.IsChanged || FBackgroundIn.IsChanged ||
                FIgnoreView.IsChanged || FViewIn.IsChanged || FResized)
            {
                FResized = false;

                FSVGDoc = new SvgDocument();
                foreach (var elem in FSVGIn)
                {
                    if (elem != null)
                    {
                        FSVGDoc.Children.Add(elem);
                    }
                }

                FSVGDoc.Transforms = new SvgTransformCollection();

                //set view
                if (!FIgnoreView[0])
                {
                    var view = FViewIn[0];

                    if (view.Equals(SvgViewBox.Empty))
                    {
                        view = new SvgViewBox(-1, -1, 2, 2);
                    }

                    FSVGDoc.ViewBox = view;
                }

                //calc size
                FSize.Width  = FSizeIn[0].X;
                FSize.Height = FSizeIn[0].Y;

                if (FSize == SizeF.Empty)
                {
                    FSize = new SizeF(this.Width, this.Height);
                }

                //set size and output doc
                FSVGDoc.Width  = new SvgUnit(SvgUnitType.User, Math.Max(FSize.Width, 1));
                FSVGDoc.Height = new SvgUnit(SvgUnitType.User, Math.Max(FSize.Height, 1));

                FOutput[0]     = new SvgDoc(FSVGDoc, FBackgroundIn[0].Color);
                FSizeOutput[0] = new Vector2(FSize.Width, FSize.Height);
            }

            //render to window
            if (FThisNode.Window != null)
            {
                if (FBitMap == null)
                {
                    FBitMap = new Bitmap((int)Math.Ceiling(FSVGDoc.Width), (int)Math.Ceiling(FSVGDoc.Height));
                }
                else if (FBitMap.Height != FSVGDoc.Height || FBitMap.Width != FSVGDoc.Width)
                {
                    FBitMap.Dispose();
                    FBitMap = new Bitmap((int)Math.Ceiling(FSVGDoc.Width), (int)Math.Ceiling(FSVGDoc.Height));
                }

                //clear bitmap
                var g = Graphics.FromImage(FBitMap);
                g.Clear(FBackgroundIn[0].Color);
                g.Dispose();

                FSVGDoc.Draw(FBitMap);
                FPicBox.Image = FBitMap;
            }
        }
Ejemplo n.º 2
0
                #pragma warning restore
        #endregion fields & pins

        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (InputChanged() || FBackgroundIn.IsChanged || FReloadIn[0])
            {
                FDocOut.SliceCount     = SpreadMax;
                FLayerOut.SliceCount   = SpreadMax;
                FViewOut.SliceCount    = SpreadMax;
                FHasViewOut.SliceCount = SpreadMax;
                FSizeOut.SliceCount    = SpreadMax;
                FHasSizeOut.SliceCount = SpreadMax;

                for (int i = 0; i < SpreadMax; i++)
                {
                    var doc = ReadDocument(i);

                    if (doc != null)
                    {
                        FDocOut[i] = new SvgDoc(doc, FBackgroundIn[i].Color);

                        var spread = FLayerOut[i];
                        spread.SliceCount = doc.Children.Count;

                        for (int j = 0; j < spread.SliceCount; j++)
                        {
                            spread[j] = doc.Children[j];
                        }

                        //check view and size
                        var noView = doc.ViewBox.Equals(SvgViewBox.Empty);

                        var hp     = new SvgUnit(SvgUnitType.Percentage, 100);
                        var noSize = (doc.Width == hp && doc.Height == hp);

                        var view = doc.ViewBox;

                        if (noView)
                        {
                            if (noSize)
                            {
                                view = doc.Bounds;
                            }
                            else
                            {
                                view = doc.GetDimensions();
                            }

                            doc.ViewBox = view;
                        }

                        if (noSize)
                        {
                            doc.Width  = new SvgUnit(SvgUnitType.User, view.Width);
                            doc.Height = new SvgUnit(SvgUnitType.User, view.Height);
                        }

                        FViewOut[i]    = view;
                        FHasViewOut[i] = !noView;
                        var size = doc.GetDimensions();
                        FSizeOut[i] = new Vector2D(size.Width, size.Height);

                        FHasSizeOut[i] = !noSize;
                    }
                    else
                    {
                        FDocOut[i] = new SvgDoc();
                        FLayerOut[i].SliceCount = 0;

                        FViewOut[i]    = new SvgViewBox();
                        FHasViewOut[i] = false;

                        FSizeOut[i]    = new Vector2D();
                        FHasSizeOut[i] = false;
                    }
                }
            }
            //FLogger.Log(LogType.Debug, "hi tty!");
        }