Пример #1
0
        public static UnsafeBitmap PackBitmaps(Vex.VexObject vo, Dictionary <uint, Rectangle> outputBitmaps)
        {
            Gdi.GdiRenderer           renderer      = new Gdi.GdiRenderer();
            Dictionary <uint, Bitmap> sourceBitmaps = renderer.GenerateMappedBitmaps(vo, true);

            if (sourceBitmaps.Count == 0)
            {
                throw new Exception("There are no symbols to arrange");
            }

            List <ArrangedBitmap> bitmaps = new List <ArrangedBitmap>();

            foreach (uint key in sourceBitmaps.Keys)
            {
                Vex.IDefinition def    = vo.Definitions[key];
                Bitmap          sbmp   = sourceBitmaps[key];
                ArrangedBitmap  bitmap = new ArrangedBitmap();
                bitmap.Width  = sbmp.Width + 2;
                bitmap.Height = sbmp.Height + 2;
                bitmap.Id     = def.Id;
                bitmaps.Add(bitmap);
            }

            Size bmpSize = ProcessRectangles(bitmaps);

            return(CopyBitmapsToOutput(bitmaps, sourceBitmaps, outputBitmaps, bmpSize.Width, bmpSize.Height));
        }
Пример #2
0
 public Bitmap RenderFirstFrame(Vex.IDefinition def, Vex.Matrix m)
 {
     using (Matrix sm = new Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, 0, 0))
     {
         return(RenderDefinitionFrames(def, 0, 1, sm)[0]);
     }
 }
Пример #3
0
 public LibraryItem(StageView stage, Vex.IDefinition definition)
 {
     this.stage      = stage;
     this.definition = definition;
     this.Date       = (definition.Path == null) ? DateTime.Now.ToUniversalTime() : File.GetLastAccessTimeUtc(definition.Path);
     this.Name       = (definition.Name == null) ? null : definition.Name;
 }
Пример #4
0
 public Bitmap RenderFirstFrame(Vex.IDefinition def, Matrix m)
 {
     using (Matrix sm = new Matrix(m.Elements[0], m.Elements[1], m.Elements[2], m.Elements[3], 0, 0))
     {
         return(RenderDefinitionFrames(def, 0, 1, sm)[0]);
     }
 }
Пример #5
0
        public void AddBitmap(Vex.IDefinition def, Bitmap bmp)
        {
            long key = GetDefinitionIdentifier(def);

            bmp.Tag    = key;
            cache[key] = bmp;
        }
Пример #6
0
 public Bitmap RenderFirstFrame(Vex.IDefinition def)
 {
     using (Matrix m = new Matrix())
     {
         return(RenderDefinitionFrames(def, 0, 1, m)[0]);
     }
 }
Пример #7
0
        public static LibraryItem LoadFromPath(StageView stage, string type, string dataPath)
        {
            LibraryItem result = null;

            if (File.Exists(dataPath)) // todo: account for missing files
            {
                FileStream    fs = new FileStream(dataPath, FileMode.Open);
                XmlSerializer xs = null;
                switch (type)
                {
                case "DDW.Vex.Timeline":
                    xs = new XmlSerializer(typeof(Vex.Timeline));
                    break;

                case "DDW.Vex.Symbol":
                    xs = GetShapeSerializer();
                    break;

                case "DDW.Vex.Image":
                    xs = new XmlSerializer(typeof(Vex.Image));
                    break;
                }

                if (xs != null)
                {
                    Vex.IDefinition def = (Vex.IDefinition)xs.Deserialize(fs);
                    result      = new LibraryItem(stage, def);
                    result.date = File.GetLastWriteTimeUtc(dataPath);
                    result.HasSaveableChanges = false;
                }

                fs.Close();
            }
            return(result);
        }
Пример #8
0
        public void RenderInto(Vex.IDefinition def, uint frame, Graphics graphics)
        {
            this.g = graphics;

            if (def is Vex.Timeline)
            {
                Vex.Timeline tl          = (Vex.Timeline)def;
                Vex.Timeline namedSymbol = GetNamedSymbol(tl);
                if (namedSymbol != null)// && HasSymbols(namedSymbol))
                {
                    RenderFrame(namedSymbol, frame);
                }
            }
            else if (def is Vex.Symbol)
            {
                Vex.Symbol sy = (Vex.Symbol)def;
                RenderFrame(sy, 0);
            }
            else if (def is Vex.Text)
            {
                Vex.Text tx = (Vex.Text)def;
                if (tx.TextRuns.Count > 0 && !tx.TextRuns[0].isEditable)
                {
                    RenderFrame(tx, 0);
                }
            }
            else if (def is Vex.Image)
            {
                Bitmap sourceBmp = stage.BitmapCache.GetBitmap(def);
                DrawImage(sourceBmp);
            }
        }
Пример #9
0
        public Bitmap GetBitmap(Vex.IDefinition def)
        {
            Bitmap result = null;

            long key = GetDefinitionIdentifier(def);

            if (cache.ContainsKey(key))
            {
                result = cache[key];
            }
            else if (def.Path != null)// if (def.StrokeBounds == Vex.Rectangle.Empty) // from file, not swf
            {
                string path = File.Exists(def.Path) ? def.Path : stage.DefinitionsFolderFull + def.Path;
                Image  img  = LoadImageNoLock(path);
                result = new Bitmap(img);
                img.Dispose();

                result.SetResolution(96, 96);
                def.StrokeBounds = new Vex.Rectangle(0, 0, result.Width, result.Height);
                result.Tag       = key;
                cache[key]       = result;
            }

            return(result);
        }
Пример #10
0
        public void RenderOutlineInto(Vex.IDefinition def, uint frame, Graphics graphics)
        {
            penOverride  = outlinePen;
            fillOverride = (SolidBrush)Brushes.Transparent;

            RenderInto(def, frame, graphics);

            fillOverride = null;
            penOverride  = null;
        }
Пример #11
0
        public void RemoveBitmap(Vex.IDefinition def)
        {
            long key = GetDefinitionIdentifier(def);

            if (cache.ContainsKey(key))
            {
                Bitmap bmp = cache[key];
                cache.Remove(key);
                bmp.Dispose();
            }
        }
Пример #12
0
        public void RenderMaskInto(Vex.IDefinition def, uint frame, Graphics graphics, Color c)
        {
            penOverride  = new Pen(c, 1);
            fillOverride = new SolidBrush(c);

            RenderInto(def, frame, graphics);

            fillOverride.Dispose();
            fillOverride = null;
            penOverride.Dispose();
            penOverride = null;
        }
Пример #13
0
        public bool HasSymbols(Vex.Timeline tl)
        {
            bool result = false;

            for (int i = 0; i < tl.InstanceCount; i++)
            {
                Vex.IDefinition idef = stage.Library[tl.InstanceAt(i).DefinitionId].Definition;
                if (idef is Vex.Symbol)
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Пример #14
0
 private void DrawTimeline(Vex.Timeline tl)
 {
     for (int i = 0; i < tl.InstanceCount; i++)
     {
         Vex.IDefinition idef = stage.Library[tl.InstanceAt(i).DefinitionId].Definition;
         if (idef is Vex.Symbol)
         {
             DrawSymbol((Vex.Symbol)idef);
         }
         else if (idef is Vex.Timeline)
         {
             DrawTimeline((Vex.Timeline)idef);
         }
     }
 }
Пример #15
0
 // filtered meaning remove annotations like box2d bounding boxes
 private void DrawFilteredTimeline(Vex.Timeline tl, uint frame)
 {
     for (int i = 0; i < tl.InstanceCount; i++)
     {
         Vex.Instance inst = (Vex.Instance)tl.InstanceAt(i);
         if (inst.GetTransformAtTime(frame) != null)
         {
             Vex.IDefinition idef = stage.Library[inst.DefinitionId].Definition;
             if (idef is Vex.Symbol || idef is Vex.Timeline)
             {
                 GraphicsState gs = g.Save();
                 using (Matrix nm = inst.GetTransformAtTime(0).Matrix.GetDrawing2DMatrix())
                 {
                     nm.Multiply(g.Transform, MatrixOrder.Append);
                     g.Transform = nm;
                     if (idef is Vex.Symbol)
                     {
                         DrawFilteredSymbol((Vex.Symbol)idef);
                     }
                     else
                     {
                         DrawFilteredTimeline((Vex.Timeline)idef, frame);
                     }
                 }
                 g.Restore(gs);
             }
             else if (idef is Vex.Text)
             {
                 DrawText((Vex.Text)idef, inst.Transformations[0].Matrix);
             }
             else if (idef is Vex.Image)
             {
                 Matrix pm = g.Transform.Clone();
                 Matrix nm = inst.GetTransformAtTime(0).Matrix.GetDrawing2DMatrix();
                 nm.Multiply(pm, MatrixOrder.Append);
                 g.Transform = nm;
                 DrawImage(stage.BitmapCache.GetBitmap(idef));
                 g.Transform = pm;
             }
         }
     }
 }
Пример #16
0
        public void RenderInto(Vex.IDefinition def, uint frame, Bitmap image)
        {
            SizeF targSize   = image.Size;
            SizeF sourceSize = def.StrokeBounds.Size.SysSize();

            if (sourceSize.Width != 0 && sourceSize.Height != 0)
            {
                float wRatio = targSize.Width / sourceSize.Width;
                float hRatio = targSize.Height / sourceSize.Height;

                float finalRatio;
                int   offsetX = 0;
                int   offsetY = 0;
                if (wRatio > hRatio)
                {
                    finalRatio = hRatio;
                    offsetX    = (int)((targSize.Width - sourceSize.Width * hRatio) / 2.0);
                }
                else
                {
                    finalRatio = wRatio;
                    offsetY    = (int)((targSize.Height - sourceSize.Height * wRatio) / 2.0);
                }

                Matrix translateMatrix = new Matrix(
                    finalRatio, 0, 0, finalRatio,
                    -def.StrokeBounds.Point.X * finalRatio + offsetX,
                    -def.StrokeBounds.Point.Y * finalRatio + offsetY);
                this.g = GetGraphicsFromBitmap(image);

                this.g.Clear(Color.Transparent);
                this.g.Transform = translateMatrix;

                RenderFrame(def, 0);

                this.g.Transform.Dispose();
                this.g.Dispose();
                this.g = null;
            }
        }
Пример #17
0
        private Vex.Timeline GetNamedSymbol(Vex.Timeline tl)
        {
            Vex.Timeline result = null;

            if (tl.Name != "")
            {
                result = tl;
            }
            else
            {
                for (int i = 0; i < tl.InstanceCount; i++)
                {
                    Vex.IDefinition idef = stage.Library[tl.InstanceAt(i).DefinitionId].Definition;
                    if (idef is Vex.Timeline && ((Vex.Timeline)idef).Name != "")
                    {
                        result = (Vex.Timeline)idef;
                    }
                }
            }

            return(result);
        }
Пример #18
0
        // assumes graphics, matrix are setup
        private void RenderFrame(Vex.IDefinition def, uint frame)
        {
            if (def is Vex.Timeline)
            {
                DrawFilteredTimeline((Vex.Timeline)def, frame);
            }
            else if (def is Vex.Symbol)
            {
                DrawFilteredSymbol((Vex.Symbol)def);
            }
            else if (def is Vex.Text)
            {
                Vex.Text tx = (Vex.Text)def;

                if (tx.TextRuns.Count > 0 && !tx.TextRuns[0].isEditable)
                {
                    DrawText(tx, new DDW.Vex.Matrix(1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y));
                }
            }
            else if (def is Vex.Image)
            {
                DrawImage(stage.BitmapCache.GetBitmap(def));
            }
        }
Пример #19
0
        public LibraryItem[] AddSwf(string path)
        {
            List <LibraryItem> result = new List <LibraryItem>();

            if (File.Exists(path))
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    BinaryReader br = new BinaryReader(fs);

                    string    name = Path.GetFileNameWithoutExtension(path);
                    SwfReader r    = new SwfReader(br.ReadBytes((int)fs.Length));

                    SwfCompilationUnit scu = new SwfCompilationUnit(r);

                    if (scu.IsValid)
                    {
                        SwfToVex      s2v          = new SwfToVex();
                        Vex.VexObject v            = s2v.Convert(scu);
                        DateTime      creationTime = File.GetLastWriteTimeUtc(path);

                        string swfName = Path.GetFileName(path);

                        string wf = MainForm.CurrentStage.WorkingFolderFull;
                        bool   inWorkingFolder = path.IndexOf(wf) == 0;
                        string wp          = inWorkingFolder ? path.Substring(wf.Length) : swfName;
                        string workingPath = wp.Substring(0, wp.Length - swfName.Length);

                        TreeNode existingNode  = symbolTree.GetNode(workingPath, swfName);
                        bool     isUpdatingSwf = (existingNode != null);

                        LibraryItem             li;
                        Dictionary <uint, uint> translator      = new Dictionary <uint, uint>();
                        List <uint>             recycledInstIds = new List <uint>();
                        foreach (uint key in v.Definitions.Keys)
                        {
                            Vex.IDefinition loadedDef = v.Definitions[key];
                            if (scu.SymbolClasses.ContainsKey(key))
                            {
                                loadedDef.Name = scu.SymbolClasses[key];
                            }
                            uint loadedId   = loadedDef.Id;
                            bool isTimeline = loadedDef is Vex.Timeline;

                            LibraryItem existingLi = null;
                            if (isUpdatingSwf)
                            {
                                loadedDef.HasSaveableChanges = true;
                                existingLi = isTimeline ? MainForm.CurrentLibrary.GetLibraryItem(workingPath + swfName, loadedDef.Name) : MainForm.CurrentLibrary.GetByOriginalSourceId(loadedDef.Id);
                            }

                            if (existingLi != null)
                            {
                                loadedDef.Id         = existingLi.DefinitionId;
                                translator[loadedId] = loadedDef.Id;
                                existingLi.Date      = creationTime;
                                if (isTimeline)
                                {
                                    Vex.Timeline    orgTl     = (Vex.Timeline)existingLi.Definition;
                                    Vex.IInstance[] instances = orgTl.Instances.ToArray();
                                    for (int i = 0; i < instances.Length; i++)
                                    {
                                        recycledInstIds.Add(instances[i].InstanceHash);
                                        orgTl.RemoveInstance(instances[i]);
                                        MainForm.CurrentStage.InstanceManager.RemoveInstance(instances[i].InstanceHash);
                                    }
                                }
                                MainForm.CurrentStage.vexObject.Definitions[loadedDef.Id] = loadedDef;
                                existingLi.Definition = loadedDef;
                            }
                            else
                            {
                                li                   = MainForm.CurrentStage.CreateLibraryItem(loadedDef, false);
                                li.Date              = creationTime;
                                li.LibraryPath       = workingPath + swfName;
                                li.OriginalSourceId  = loadedId;
                                translator[loadedId] = li.Definition.Id;

                                if (isTimeline)
                                {
                                    result.Add(li);
                                    AddItemToLibrary(li);
                                }
                            }

                            if (isTimeline)
                            {
                                Vex.Timeline tl = (Vex.Timeline)loadedDef;
                                for (int i = 0; i < tl.InstanceCount; i++)
                                {
                                    Vex.IInstance inst = tl.InstanceAt(i);
                                    if (recycledInstIds.Count > 0)
                                    {
                                        inst.InstanceHash = recycledInstIds[0];
                                        recycledInstIds.RemoveAt(0);
                                    }

                                    inst.DefinitionId       = translator[inst.DefinitionId];
                                    inst.ParentDefinitionId = translator[inst.ParentDefinitionId];
                                    MainForm.CurrentStage.CreateInstance((Vex.Instance)inst);
                                }
                            }
                        }
                    }
                }
            }
            return(result.ToArray());
        }
Пример #20
0
 private long GetDefinitionIdentifier(Vex.IDefinition def)
 {
     return(def.Id);
 }
Пример #21
0
        public List <Bitmap> RenderDefinitionFrames(Vex.IDefinition def, uint startFrame, uint endFrame, Matrix m)
        {
            List <Bitmap> bmpFrames = new List <Bitmap>();

            if (def is Vex.Timeline)
            {
                Vex.Timeline tl          = (Vex.Timeline)def;
                Vex.Timeline namedSymbol = GetNamedSymbol(tl);
                if (namedSymbol != null)// && HasSymbols(namedSymbol))
                {
                    for (uint i = startFrame; i < endFrame; i++)
                    {
                        m.Translate(-namedSymbol.StrokeBounds.Point.X, -namedSymbol.StrokeBounds.Point.Y);
                        Bitmap myBitmap = CreateRenderBitmap(namedSymbol.StrokeBounds, m);
                        RenderFrame(namedSymbol, i);
                        bmpFrames.Add(myBitmap);
                    }
                }
            }
            else if (def is Vex.Symbol)
            {
                Vex.Symbol sy = (Vex.Symbol)def;

                m.Translate(-sy.StrokeBounds.Point.X, -sy.StrokeBounds.Point.Y);
                Bitmap myBitmap = CreateRenderBitmap(sy.StrokeBounds, m);

                RenderFrame(sy, 0);
                bmpFrames.Add(myBitmap);
            }
            else if (def is Vex.Text)
            {
                Vex.Text tx = (Vex.Text)def;

                if (tx.TextRuns.Count > 0 && !tx.TextRuns[0].isEditable)
                {
                    Bitmap myBitmap = CreateRenderBitmap(tx.StrokeBounds, m);
                    RenderFrame(tx, 0);
                    bmpFrames.Add(myBitmap);
                }
            }
            else if (def is Vex.Image)
            {
                Bitmap myBitmap;
                m.Translate(-def.StrokeBounds.Point.X, -def.StrokeBounds.Point.Y);
                if (m.IsScaledOrSheared())
                {
                    myBitmap = CreateRenderBitmap(def.StrokeBounds, m);
                    Bitmap sourceBmp = stage.BitmapCache.GetBitmap(def);
                    using (Graphics gr = Graphics.FromImage(myBitmap))
                    {
                        gr.DrawImage(sourceBmp, 0, 0, myBitmap.Width, myBitmap.Height);
                    }
                }
                else
                {
                    myBitmap = stage.BitmapCache.GetBitmap(def);
                }

                bmpFrames.Add(myBitmap);
            }

            if (g != null)
            {
                g.Dispose();
            }

            return(bmpFrames);
        }
Пример #22
0
 public static RectangleF GetTransformedBounds(Vex.IDefinition def, Matrix m, bool invert)
 {
     PointF[] pts = def.StrokeBounds.SysPointFs();
     TransformPoints(pts, m, invert);
     return(pts.GetBounds());
 }
Пример #23
0
        public Vex.Rectangle GetBounds(Vex.IDefinition def)
        {
            Bitmap bmp = GetBitmap(def);

            return(new Vex.Rectangle(0, 0, bmp.Width, bmp.Height));
        }