Пример #1
0
		public VexObject Convert(SwfCompilationUnit swf)
		{
			this.swf = swf;
			this.v = new VexObject(swf.Name);
			Log = new StringBuilder();

			RootTimeline = new Timeline(v.NextId());
			RootTimeline.Name = "_root";

			this.curTimeline = RootTimeline;
			curTimeline.FrameCount = swf.Header.FrameCount;
			curTimeline.Duration = GetDuration(swf.Header.FrameCount);

			v.Root = curTimeline;
			this.curDepthChart = rootDepthChart;

			this.ParseHeader();
			foreach(ISwfTag tag in swf.Tags)
			{
				this.ParseTag(tag);
			}

			WriteEndTimes();
			return v;
		}
Пример #2
0
        public static string Convert(string fileName, out SwfCompilationUnit scu, out VexObject v)
        {
            v = null;
            string result = "Failed to convert.";
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            string name = Path.GetFileNameWithoutExtension(fileName);
            SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length));
            scu = new SwfCompilationUnit(r, name);
            if (scu.IsValid)
            {
                result = "\n\n**** Converting to SwfCompilationUnit ****\n";

            #if DEBUG
                StringWriter sw = new StringWriter();
                IndentedTextWriter w = new IndentedTextWriter(sw);
                scu.Dump(w);
                Debug.WriteLine(sw.ToString());
            #endif

                result += scu.Log.ToString();

                SwfToVex s2v = new SwfToVex();
                v = s2v.Convert(scu);
                result += "\n\n**** Converting to Vex ****\n";
                result += s2v.Log.ToString();
            }
            return result;
        }
Пример #3
0
 public void AddShapes(VexObject vo, IDefinition def, Matrix m)
 {
     if (def.Name == "circleShape")
     {
         //Matrix m = orgInst.Transformations[0].Matrix;
         Point c = new Point(m.TranslateX, m.TranslateY);
         float r = m.ScaleX * 100 / 2;
         Shapes.Add(new CircleShape2D(def.Name, c, r));
     }
     else if (def is Symbol)
     {
         //Matrix m = orgInst.Transformations[0].Matrix;
         AddShape(def.Name, (Symbol)def, m);
     }
     else if (def is Timeline)
     {
         foreach (Instance inst in ((Timeline)def).Instances)
         {
             IDefinition def2 = vo.Definitions[inst.DefinitionId];
             if (def2 is Symbol && (def2.UserData & (int)DefinitionKind.OutlineStroke) != 0)
             {
                 //todo: Symbol may have multiple Shapes, and only one/some are red outlines
                 //Matrix m = inst.Transformations[0].Matrix;
                 AddShape(def.Name, (Symbol)def2, inst.Transformations[0].Matrix);
             }
         }
     }
 }
Пример #4
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));
        }
Пример #5
0
 public List<Bitmap> GenerateBitmaps(VexObject v)
 {
     List<Bitmap> result = new List<Bitmap>();
     Dictionary<uint, Bitmap> dbmp = GenerateMappedBitmaps(v, false);
     result.AddRange(dbmp.Values);
     return result;
 }
Пример #6
0
        public override void GenerateXaml(VexObject v, out string xamlFileName)
        {
            this.v = v;
            this.Log = new StringBuilder();
            xamlFileName = Directory.GetCurrentDirectory() + "/" + v.Name + ".xaml";
            xw = new XamlWriter(xamlFileName, Encoding.UTF8);

            xw.WriteComment(headerComment);

            #if(IS_TRIAL)
            // turn off watermarking for small files
            isWatermarking = true;
            xw.WriteComment(trialComment);
            if (v.Definitions.Count < 15)
            {
                isWatermarking = false;
            }
            #else
            isWatermarking = false;
            #endif

            xw.OpenHeaderTag(v.ViewPort.Size.Width, v.ViewPort.Size.Height, v.BackgroundColor);

            WriteDefinitions(v.Definitions, true, false);

            WriteTimelineDefiniton(v.Root, true);

            xw.CloseHeaderTag();

            xw.Close();
        }
Пример #7
0
        public static VexObject Load(string fileFullPathAndName)
        {
            VexObject vo;
            string rootFolder = Path.GetDirectoryName(fileFullPathAndName);
            string fileNameOnly = Path.GetFileNameWithoutExtension(fileFullPathAndName);
            Environment.CurrentDirectory = rootFolder;

            string definitionsFolder = "";
            string instancesFolder = "";
            uint rootId = 0;

            vo = new VexObject(fileNameOnly);

            FileStream fs = new FileStream(fileFullPathAndName, FileMode.Open);
            XmlTextReader r = new XmlTextReader(fs);

            r.ReadStartElement("UIL");

            while (r.Read())
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                        case "DefinitionsFolder":
                            if (r.Read())
                            {
                                definitionsFolder = r.Value.Trim();
                            }
                            break;
                        case "InstancesFolder":
                            if (r.Read())
                            {
                                instancesFolder = r.Value.Trim();
                            }
                            break;
                        case "RootId":
                            if (r.Read())
                            {
                                rootId = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                            }
                            break;
                    }
                }
            }

            fs.Close();

            string defsPath = rootFolder + Path.DirectorySeparatorChar + fileNameOnly + definitionsFolder;
            LoadDefinitions(defsPath, vo);

            string instsPath = rootFolder + Path.DirectorySeparatorChar + fileNameOnly + instancesFolder;
            LoadInstances(instsPath, vo);

            vo.Root = (Timeline)vo.Definitions[rootId];

            return vo;
        }
Пример #8
0
        public static string Convert(
			string fileName, 
			bool isSilverlight,
			out SwfCompilationUnit scu, 
			out VexObject v, 
			out string xamlFileName)
        {
            string result = "Failed to convert.";
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            string name = Path.GetFileNameWithoutExtension(fileName);
            SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length));
            scu = new SwfCompilationUnit(r, name);
            if (scu.IsValid)
            {
                result = "\n\n**** Converting to SwfCompilationUnit ****\n";
            #if DEBUG
                    StringWriter sw = new StringWriter();
                    IndentedTextWriter w = new IndentedTextWriter(sw);
                    scu.Dump(w);
                    Debug.WriteLine(sw.ToString());
            #endif
                result += scu.Log.ToString();

                SwfToVex s2v = new SwfToVex();
                v = s2v.Convert(scu);
                result += "\n\n**** Converting to Vex ****\n";
                result += s2v.Log.ToString();

                XamlRenderer xr;
                if (isSilverlight)
                {
                    xr = new Silverlight10Renderer();
                }
                else
                {
                    xr = new WPFRenderer();
                }
                xr.GenerateXaml(v, out xamlFileName);
                result += "\n\n**** Converting to Xaml ****\n";
                result += xr.Log.ToString();
                result += "\n\nSuccess.";
            }
            else
            {
                result = "Not a valid swf file: " + fileName;
                v = null;
                xamlFileName = "";
            }
            return result;
        }
Пример #9
0
        public void Convert(VexObject vo, DDW.Swf.SwfCompilationUnit scu)
        {
            curVo = vo;
            this.scu = scu;
            Init();
            FilterMarkers();
            ParseActions();
            ParseTimeline(curVo.Root);
            GenerateWorldActionData(); // temp
            GenerateBitamps();

            //genV2d = new GenV2DWorld(this, paths);
            //genV2d.Generate();
        }
Пример #10
0
        public DrawObject(VexObject vo)
        {
            List<Image> allImages = vo.GetAllImages();
            List<Symbol> allSymbols = vo.GetAllSymbols();
            List<Timeline> allTimelines = vo.GetAllTimelines();

            GenerateNameTables(allTimelines);
            //GetColorNames(allSymbols);

            GetFillsAndStrokes(allSymbols);
            GetDrawSymbols(allSymbols);
            GetDrawImages(allImages);
            GetDrawTimelines(allTimelines);
        }
Пример #11
0
 private static void DumpTextObject(VexObject vo)
 {
     foreach(uint key in vo.Definitions.Keys)
     {
         IDefinition def = vo.Definitions[key];
         if (def is Text)
         {
             string s = "";
             Text t = (Text)def;
             for (int i = 0; i < t.TextRuns.Count; i++)
             {
                 s += t.TextRuns[i].Text;
             }
             Console.WriteLine(s);
         }
     }
 }
Пример #12
0
        public void GenerateJsonData(VexObject vo, string path, out string filename)
        {
            StringBuilder sb = new StringBuilder();

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            DrawObject drawObject = new DrawObject(vo);
            drawObject.ToJson(sb);

            string dataName = vo.Name + "Data";
            string prefix = "var " + dataName + " = ";
            string suffix = "\n;\nvar data = " + dataName + ";\n";

            filename = path + dataName + ".js";
            File.WriteAllText(filename, prefix + sb.ToString() + suffix);
        }
Пример #13
0
        public void Convert(VexObject vo, DDW.Swf.SwfCompilationUnit scu)
        {
            curVo = vo;
            Init(scu);
            FilterMarkers();
            ParseActions(scu);
            ParseRootTimeline();
            ParseNamedDefinitions();
            GenerateWorldActionData();

            Gdi.GdiRenderer gr = new Gdi.GdiRenderer();
            Dictionary<string, List<Bitmap>> bmps = new Dictionary<string, List<Bitmap>>();
            gr.GenerateFilteredBitmaps(vo, usedImages, bmps);

            gr.ExportBitmapsAsPremultiplied(bmps);

            genV2d = new GenV2DWorld(this, usedImages);
            genV2d.Generate();
        }
Пример #14
0
        public void GenerateBinaryData(VexObject vo, string path, out string filename)
        {
            string dataName = vo.Name + "Data";
            filename = path + dataName + ".dat";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            FileStream stream = new FileStream(filename, FileMode.Create);
            VexDrawWriter writer = new VexDrawWriter(stream);

            DrawObject drawObject = new DrawObject(vo);
            writer.WriteDrawObject(drawObject);

            stream.Flush();

            //byte[] bytes = stream.ToArray();
            stream.Close();
        }
Пример #15
0
        public override void GenerateXamlPart(VexObject v, IDefinition def, out string xamlFileName)
        {
            this.v = v;
            this.Log = new StringBuilder();
            xamlFileName = Directory.GetCurrentDirectory() + "/" + v.Name + "_" + def.Id + ".xaml";
            xw = new XamlWriter(xamlFileName, Encoding.UTF8);

            xw.WriteComment(headerComment);

            #if(IS_TRIAL)
            // turn off watermarking for small files
            isWatermarking = true;
            xw.WriteComment(trialComment);
            if (v.Definitions.Count < 15)
            {
                isWatermarking = false;
            }
            #else
            isWatermarking = false;
            #endif

            xw.OpenHeaderTag(def.StrokeBounds.Size.Width, def.StrokeBounds.Size.Height, v.BackgroundColor);

            Dictionary<uint, IDefinition> defList = new Dictionary<uint, IDefinition>();
            defList.Add(1, def);
            WriteDefinitions(defList, true, true);

            //WriteTimelineDefiniton(v.Root, true);
            // Write a rectangle to hold this shape
            Instance inst = new Instance();
            inst.Name = instancePrefix + def.Id;
            inst.InstanceID = 1;
            inst.DefinitionId = def.Id;
            inst.Transformations.Add(new Transform(0, 1000, Matrix.Identitiy, 1, ColorTransform.Identity));
            WriteInstance(def, inst);

            xw.CloseHeaderTag();

            xw.Close();
        }
Пример #16
0
        /// <summary>
        /// Generates a dictionary of Symbol id and rendered bitmap.
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public Dictionary<uint, Bitmap> GenerateMappedBitmaps(VexObject v, bool includeImages)
        {
            Dictionary<uint, Bitmap> result = new Dictionary<uint, Bitmap>();

            foreach (uint key in v.Definitions.Keys)
            {
                IDefinition def = v.Definitions[key];
                if (def is Symbol)
                {
                    Symbol symbol = (Symbol)def;
                    Bitmap myBitmap = new Bitmap(
                        (int)symbol.StrokeBounds.Size.Width + 1,
                        (int)symbol.StrokeBounds.Size.Height + 1);
                    myBitmap.SetResolution(96, 96);

                    translateMatrix = new System.Drawing.Drawing2D.Matrix(
                        1, 0, 0, 1, -symbol.StrokeBounds.Point.X, -symbol.StrokeBounds.Point.Y);
                    g = Graphics.FromImage(myBitmap);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CompositingMode = CompositingMode.SourceOver;
                    g.CompositingQuality = CompositingQuality.AssumeLinear;

                    DrawSymbol(symbol);

                    result.Add(symbol.Id, myBitmap);
                    translateMatrix.Dispose();
                }
                else if (includeImages && def is Vex.Image)
                {
                    Bitmap bmp = new Bitmap(def.Path);
                    result.Add(def.Id, bmp);
                }
            }
            return result;
        }
Пример #17
0
		public void GenerateXaml(VexObject v)
		{
			string xamlFileName;
			GenerateXaml(v, out xamlFileName);
		}
Пример #18
0
		public abstract void GenerateXaml(VexObject v, out string xamlFileName);
Пример #19
0
        private Timeline GetNamedSymbol(VexObject v, Timeline tl)
        {
            Timeline result = null;

            if (tl.Name != "")
            {
                result = tl;
            }
            else
            {
                for (int i = 0; i < tl.Instances.Count; i++)
                {
                    uint defId = tl.Instances[i].DefinitionId;
                    if (v.Definitions[defId] is Timeline && ((Timeline)v.Definitions[defId]).Name != "")
                    {
                        result = (Timeline)(v.Definitions[defId]);
                    }
                }
            }

            return result;
        }
Пример #20
0
        public void GenerateFilteredBitmaps(VexObject v, Dictionary<string, IDefinition> usedImages, Dictionary<string, List<Bitmap>> genImages)
        {
            foreach (string s in usedImages.Keys)
            {
                uint key = usedImages[s].Id;
                IDefinition def = v.Definitions[key];
                if (def is Timeline)
                {
                    Timeline tl = (Timeline)def;
                    Timeline namedSymbol = GetNamedSymbol(v, tl);
                    if (namedSymbol != null && HasSymbols(v, namedSymbol))
                    {
                        List<Bitmap> bmpFrames = new List<Bitmap>();

                        for (int i = 0; i < tl.FrameCount; i++)
                        {
                            Bitmap myBitmap = new Bitmap(
                                (int)namedSymbol.StrokeBounds.Size.Width + 1,
                                (int)namedSymbol.StrokeBounds.Size.Height + 1);

                            myBitmap.SetResolution(96, 96);
                            translateMatrix = new System.Drawing.Drawing2D.Matrix(
                                1, 0, 0, 1, -namedSymbol.StrokeBounds.Point.X, -namedSymbol.StrokeBounds.Point.Y);
                            g = Graphics.FromImage(myBitmap);
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            g.CompositingMode = CompositingMode.SourceOver;
                            g.CompositingQuality = CompositingQuality.AssumeLinear;

                            DrawFilteredTimeline(v, namedSymbol);
                            translateMatrix.Dispose();
                            bmpFrames.Add(myBitmap);
                        }

                        string name = s + "#" + namedSymbol.Id;
                        genImages.Add(name, bmpFrames);
                    }
                }
                else if (def is Symbol)
                {
                    Symbol sy = (Symbol)def;
                    List<Bitmap> bmpFrames = new List<Bitmap>();

                    Bitmap myBitmap = new Bitmap(
                        (int)sy.StrokeBounds.Size.Width + 1,
                        (int)sy.StrokeBounds.Size.Height + 1);

                    myBitmap.SetResolution(96, 96);
                    translateMatrix = new System.Drawing.Drawing2D.Matrix(
                        1, 0, 0, 1, -sy.StrokeBounds.Point.X, -sy.StrokeBounds.Point.Y);
                    g = Graphics.FromImage(myBitmap);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CompositingMode = CompositingMode.SourceOver;
                    g.CompositingQuality = CompositingQuality.AssumeLinear;

                    DrawFilteredSymbol(sy);
                    translateMatrix.Dispose();
                    bmpFrames.Add(myBitmap);

                    string name = s + "#" + sy.Id;
                    genImages.Add(name, bmpFrames);
                }
                else if (def is Text)
                {
                    Text tx = (Text)def;

                    if (tx.TextRuns.Count > 0 && !tx.TextRuns[0].isEditable)
                    {
                        List<Bitmap> bmpFrames = new List<Bitmap>();

                        Bitmap myBitmap = new Bitmap(
                            (int)tx.StrokeBounds.Size.Width + 1,
                            (int)tx.StrokeBounds.Size.Height + 1);

                        //translateMatrix = new System.Drawing.Drawing2D.Matrix(
                        //    1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y);

                        //myBitmap.SetResolution(72, 72);
                        myBitmap.SetResolution(96, 96);
                        g = Graphics.FromImage(myBitmap);

                        DrawText(tx, new DDW.Vex.Matrix(1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y));
                        //translateMatrix.Dispose();
                        bmpFrames.Add(myBitmap);

                        string name = s + "#" + tx.Id;
                        genImages.Add(name, bmpFrames);
                    }
                }
            }
        }
Пример #21
0
 private void DrawFilteredTimeline(VexObject v, Timeline tl)
 {
     for (int i = 0; i < tl.Instances.Count; i++)
     {
         Instance inst = (Instance)tl.Instances[i];
         IDefinition def = v.Definitions[inst.DefinitionId];
         if (def is Symbol)
         {
             DrawFilteredSymbol((Symbol)def);
         }
         else if (def is Timeline)
         {
             DrawFilteredTimeline(v, (Timeline)def);
         }
         else if (def is Text)
         {
             DrawText((Text)def, inst.Transformations[0].Matrix);
         }
     }
 }
Пример #22
0
 private void DrawTimeline(VexObject v, Timeline tl)
 {
     for (int i = 0; i < tl.Instances.Count; i++)
     {
         IDefinition def = v.Definitions[tl.Instances[i].DefinitionId];
         if (def is Symbol)
         {
             DrawSymbol((Symbol)def);
         }
         else if (def is Timeline)
         {
             DrawTimeline(v, (Timeline)def);
         }
     }
 }
Пример #23
0
        private static void LoadInstances(string folderPath, VexObject vo)
        {
            List<string> dataPaths = new List<string>();
            List<string> types = new List<string>();

            uint instanceIdCounter = 1;

            string libFileName = folderPath + Path.DirectorySeparatorChar + "Instances.xml";
            FileStream fs = new FileStream(libFileName, FileMode.Open);
            XmlTextReader r = new XmlTextReader(fs);
            r.WhitespaceHandling = WhitespaceHandling.None;
            r.ReadStartElement("Instances");

            do
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                        case "InstanceIdCounter":
                            if (r.Read())
                            {
                                instanceIdCounter = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                                r.Read();
                            }
                            break;

                        case "InstanceItems":
                            while (r.Read())
                            {
                                if (r.IsStartElement() && r.Name == "Item")
                                {
                                    dataPaths.Add(r.GetAttribute("DataPath"));
                                    types.Add(r.GetAttribute("Type"));
                                }
                            }
                            break;

                        default:
                            r.Read();
                            break;
                    }
                }
            }
            while (r.Read());

            r.Close();
            fs.Close();

            // read actual DesignInstance Items
            for (int i = 0; i < dataPaths.Count; i++)
            {
                string dp = folderPath + Path.DirectorySeparatorChar + dataPaths[i];
                string type = types[i];
                IInstance inst = LoadFromPath(type, dp);

                if(vo.Definitions.ContainsKey(inst.ParentDefinitionId))
                {
                    Timeline parent = (Timeline)vo.Definitions[inst.ParentDefinitionId];
                    parent.AddInstance(inst);
                }
            }

        }
Пример #24
0
        private void DrawBackground(VexObject v)
        {
            Brush b = new SolidBrush(this.GetColor(v.BackgroundColor));
            RectangleF r = new RectangleF(
                v.ViewPort.Point.X,
                v.ViewPort.Point.X,
                v.ViewPort.Size.Width,
                v.ViewPort.Size.Height);

            g.FillRectangle(b, r);
        }
Пример #25
0
        public static string Convert(
			bool isSilverlight,
			SwfCompilationUnit scu,
			VexObject v,
			out string xamlFileName)
        {
            string result = "Failed to convert.";

            SwfToVex s2v = new SwfToVex();
            v = s2v.Convert(scu);
            result = "\n\n**** Converting to Vex ****\n";
            result += s2v.Log.ToString();

            XamlRenderer xr;
            if (isSilverlight)
            {
                xr = new Silverlight10Renderer();
            }
            else
            {
                xr = new WPFRenderer();
            }
            xr.GenerateXaml(v, out xamlFileName);
            result += "\n\n**** Converting to Xaml ****\n";
            result += xr.Log.ToString();
            result += "\n\nSuccess.";

            return result;
        }
Пример #26
0
		public abstract void GenerateXamlPart(VexObject v, IDefinition def, out string xamlFileName);
Пример #27
0
        private static void LoadDefinitions(string folderPath, VexObject vo)
        {
            uint          definitionIdCounter = 1;
            List <string> dataPaths           = new List <string>();
            List <string> headerPaths         = new List <string>();
            List <string> types = new List <string>();
            List <string> names = new List <string>();

            string        libFileName = folderPath + Path.DirectorySeparatorChar + "Library.xml";
            FileStream    fs          = new FileStream(libFileName, FileMode.Open);
            XmlTextReader r           = new XmlTextReader(fs);

            r.WhitespaceHandling = WhitespaceHandling.None;
            r.ReadStartElement("Library");

            do
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                    case "LibraryIdCounter":
                        if (r.Read())
                        {
                            definitionIdCounter = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                            r.Read();
                        }
                        break;

                    case "LibraryItems":
                        while (r.Read())
                        {
                            if (r.IsStartElement() && r.Name == "Item")
                            {
                                headerPaths.Add(r.GetAttribute("HeaderPath"));
                                dataPaths.Add(r.GetAttribute("DataPath"));
                                types.Add(r.GetAttribute("Type"));
                                names.Add(r.GetAttribute("Name"));
                            }
                        }
                        break;

                    default:
                        r.Read();
                        break;
                    }
                }
            }while (r.Read());

            r.Close();
            fs.Close();

            // read actual library Items
            for (int i = 0; i < dataPaths.Count; i++)
            {
                string dp   = folderPath + Path.DirectorySeparatorChar + dataPaths[i];
                string hp   = folderPath + Path.DirectorySeparatorChar + headerPaths[i];
                string type = types[i];

                IDefinition def = LoadDefinition(type, hp, dp);
                vo.Definitions.Add(def.Id, def);
                //Name = names[i];
            }
        }
Пример #28
0
        protected void WriteSilverlightHtml(VexObject v, string fileName)
        {
            using (TextWriter tw = new StreamWriter(fileName))
            {
                tw.WriteLine(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">");
                tw.WriteLine(@"<html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"">");
                tw.WriteLine(@" <head>");
                tw.WriteLine(@"   <title>Silverlight</title>");
                tw.WriteLine(@"   <script type=""text/javascript"">");
                tw.WriteLine(@"    if(!window.Silverlight)window.Silverlight={};Silverlight._silverlightCount=0;Silverlight.ua=null;Silverlight.available=false;Silverlight.fwlinkRoot=""http://go.microsoft.com/fwlink/?LinkID="";Silverlight.StatusText=""Get Microsoft Silverlight"";Silverlight.EmptyText="""";Silverlight.detectUserAgent=function(){var a=window.navigator.userAgent;Silverlight.ua={OS:""Unsupported"",Browser:""Unsupported""};if(a.indexOf(""Windows NT"")>=0)Silverlight.ua.OS=""Windows"";else if(a.indexOf(""PPC Mac OS X"")>=0)Silverlight.ua.OS=""MacPPC"";else if(a.indexOf(""Intel Mac OS X"")>=0)Silverlight.ua.OS=""MacIntel"";if(Silverlight.ua.OS!=""Unsupported"")if(a.indexOf(""MSIE"")>=0){if(navigator.userAgent.indexOf(""Win64"")==-1)if(parseInt(a.split(""MSIE"")[1])>=6)Silverlight.ua.Browser=""MSIE""}else if(a.indexOf(""Firefox"")>=0){var b=a.split(""Firefox/"")[1].split("".""),c=parseInt(b[0]);if(c>=2)Silverlight.ua.Browser=""Firefox"";else{var d=parseInt(b[1]);if(c==1&&d>=5)Silverlight.ua.Browser=""Firefox""}}else if(a.indexOf(""Safari"")>=0)Silverlight.ua.Browser=""Safari""};Silverlight.detectUserAgent();Silverlight.isInstalled=function(d){var c=false,a=null;try{var b=null;if(Silverlight.ua.Browser==""MSIE"")b=new ActiveXObject(""AgControl.AgControl"");else if(navigator.plugins[""Silverlight Plug-In""]){a=document.createElement(""div"");document.body.appendChild(a);a.innerHTML='<embed type=""application/x-silverlight"" />';b=a.childNodes[0]}if(b.IsVersionSupported(d))c=true;b=null;Silverlight.available=true}catch(e){c=false}if(a)document.body.removeChild(a);return c};Silverlight.createObject=function(l,g,m,j,k,i,h){var b={},a=j,c=k;a.source=l;b.parentElement=g;b.id=Silverlight.HtmlAttributeEncode(m);b.width=Silverlight.HtmlAttributeEncode(a.width);b.height=Silverlight.HtmlAttributeEncode(a.height);b.ignoreBrowserVer=Boolean(a.ignoreBrowserVer);b.inplaceInstallPrompt=Boolean(a.inplaceInstallPrompt);var e=a.version.split(""."");b.shortVer=e[0]+"".""+e[1];b.version=a.version;a.initParams=i;a.windowless=a.isWindowless;a.maxFramerate=a.framerate;for(var d in c)if(c[d]&&d!=""onLoad""&&d!=""onError""){a[d]=c[d];c[d]=null}delete a.width;delete a.height;delete a.id;delete a.onLoad;delete a.onError;delete a.ignoreBrowserVer;delete a.inplaceInstallPrompt;delete a.version;delete a.isWindowless;delete a.framerate;if(Silverlight.isInstalled(b.version)){if(Silverlight._silverlightCount==0)if(window.addEventListener)window.addEventListener(""onunload"",Silverlight.__cleanup,false);else window.attachEvent(""onunload"",Silverlight.__cleanup);var f=Silverlight._silverlightCount++;a.onLoad=""__slLoad""+f;a.onError=""__slError""+f;window[a.onLoad]=function(a){if(c.onLoad)c.onLoad(document.getElementById(b.id),h,a)};window[a.onError]=function(a,b){if(c.onError)c.onError(a,b);else Silverlight.default_error_handler(a,b)};slPluginHTML=Silverlight.buildHTML(b,a)}else slPluginHTML=Silverlight.buildPromptHTML(b);if(b.parentElement)b.parentElement.innerHTML=slPluginHTML;else return slPluginHTML};Silverlight.supportedUserAgent=function(){var a=Silverlight.ua,b=a.OS==""Unsupported""||a.Browser==""Unsupported""||a.OS==""Windows""&&a.Browser==""Safari""||a.OS.indexOf(""Mac"")>=0&&a.Browser==""IE"";return !b};Silverlight.buildHTML=function(c,d){var a=[],e,i,g,f,h;if(Silverlight.ua.Browser==""Safari""){a.push(""<embed "");e="""";i="" "";g='=""';f='""';h=' type=""application/x-silverlight""/>'+""<iframe style='visibility:hidden;height:0;width:0'/>""}else{a.push('<object type=""application/x-silverlight""');e="">"";i=' <param name=""';g='"" value=""';f='"" />';h=""</object>""}a.push(' id=""'+c.id+'"" width=""'+c.width+'"" height=""'+c.height+'"" '+e);for(var b in d)if(d[b])a.push(i+Silverlight.HtmlAttributeEncode(b)+g+Silverlight.HtmlAttributeEncode(d[b])+f);a.push(h);return a.join("""")};Silverlight.default_error_handler=function(e,b){var d,c=b.ErrorType;d=b.ErrorCode;var a=""\nSilverlight error message     \n"";a+=""ErrorCode: ""+d+""\n"";a+=""ErrorType: ""+c+""       \n"";a+=""Message: ""+b.ErrorMessage+""     \n"";if(c==""ParserError""){a+=""XamlFile: ""+b.xamlFile+""     \n"";a+=""Line: ""+b.lineNumber+""     \n"";a+=""Position: ""+b.charPosition+""     \n""}else if(c==""RuntimeError""){if(b.lineNumber!=0){a+=""Line: ""+b.lineNumber+""     \n"";a+=""Position: ""+b.charPosition+""     \n""}a+=""MethodName: ""+b.methodName+""     \n""}alert(a)};Silverlight.createObjectEx=function(b){var a=b,c=Silverlight.createObject(a.source,a.parentElement,a.id,a.properties,a.events,a.initParams,a.context);if(a.parentElement==null)return c};Silverlight.buildPromptHTML=function(i){var a=null,f=Silverlight.fwlinkRoot,c=Silverlight.ua.OS,b=""92822"",d;if(i.inplaceInstallPrompt){var h;if(Silverlight.available){d=""94376"";h=""94382""}else{d=""92802"";h=""94381""}var g=""93481"",e=""93483"";if(c==""Windows""){b=""92799"";g=""92803"";e=""92805""}else if(c==""MacIntel""){b=""92808"";g=""92804"";e=""92806""}else if(c==""MacPPC""){b=""92807"";g=""92815"";e=""92816""}a='<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""205px""><tr><td><img title=""Get Microsoft Silverlight"" onclick=""javascript:Silverlight.followFWLink({0});"" style=""border:0; cursor:pointer"" src=""{1}""/></td></tr><tr><td style=""background:#C7C7BD; text-align: center; color: black; font-family: Verdana; font-size: 9px; padding-bottom: 0.05cm; ;padding-top: 0.05cm"" >By clicking <b>Get Microsoft Silverlight</b> you accept the <a title=""Silverlight License Agreement"" href=""{2}"" target=""_top"" style=""text-decoration: underline; color: #36A6C6""><b>Silverlight license agreement</b></a>.</td></tr><tr><td style=""border-left-style: solid; border-right-style: solid; border-width: 2px; border-color:#c7c7bd; background: #817d77; color: #FFFFFF; text-align: center; font-family: Verdana; font-size: 9px"">Silverlight updates automatically, <a title=""Silverlight Privacy Statement"" href=""{3}"" target=""_top"" style=""text-decoration: underline; color: #36A6C6""><b>learn more</b></a>.</td></tr><tr><td><img src=""{4}""/></td></tr></table>';a=a.replace(""{2}"",f+g);a=a.replace(""{3}"",f+e);a=a.replace(""{4}"",f+h)}else{if(Silverlight.available)d=""94377"";else d=""92801"";if(c==""Windows"")b=""92800"";else if(c==""MacIntel"")b=""92812"";else if(c==""MacPPC"")b=""92811"";a='<div style=""width: 205px; height: 67px; background-color: #FFFFFF""><img onclick=""javascript:Silverlight.followFWLink({0});"" style=""border:0; cursor:pointer"" src=""{1}"" alt=""Get Microsoft Silverlight""/></div>'}a=a.replace(""{0}"",b);a=a.replace(""{1}"",f+d);return a};Silverlight.__cleanup=function(){for(var a=Silverlight._silverlightCount-1;a>=0;a--){window[""__slLoad""+a]=null;window[""__slError""+a]=null}if(window.removeEventListener)window.removeEventListener(""unload"",Silverlight.__cleanup,false);else window.detachEvent(""onunload"",Silverlight.__cleanup)};Silverlight.followFWLink=function(a){top.location=Silverlight.fwlinkRoot+String(a)};Silverlight.HtmlAttributeEncode=function(c){var a,b="""";if(c==null)return null;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);if(a>96&&a<123||a>64&&a<91||a>43&&a<58&&a!=47||a==95)b=b+String.fromCharCode(a);else b=b+""&#""+a+"";""}return b}");

                tw.Write(@"    function createMySilverlightPlugin(){Silverlight.createObject(""");
                int index = fileName.LastIndexOf(v.Name);
                string xamlName = fileName.Substring(index);
                xamlName = xamlName.Replace(".html", ".xaml");
                tw.Write(xamlName); // name
                tw.Write(@""",parentElement,""mySilverlightPlugin"",{width:'");
                tw.Write(v.ViewPort.Size.Width);			// width
                tw.Write(@"',height:'");
                tw.Write(v.ViewPort.Size.Height);			// height
                tw.Write(@"',inplaceInstallPrompt:true,background:'#");
                tw.Write(v.BackgroundColor.Value.ToString("X6"));		// color
                tw.Write(@"',isWindowless:'false',framerate:'");
                tw.Write(v.FrameRate);			// frame rate
                tw.WriteLine(@"',version:'1.0'},{onError:null,onLoad:null},null);}");

                tw.WriteLine(@"   </script>");
                tw.WriteLine(@" </head>");
                tw.WriteLine(@" <body>");
                tw.WriteLine(@"	 <div id=""mySilverlightPluginHost""> </div>");
                tw.WriteLine(@"	 <script type=""text/javascript"">");
                tw.WriteLine(@"	 var parentElement = document.getElementById(""mySilverlightPluginHost"");");
                tw.WriteLine(@"	 createMySilverlightPlugin();");
                tw.WriteLine(@"	 </script>");
                tw.WriteLine(@" </body>");
                tw.WriteLine(@"</html>");
            }
        }
Пример #29
0
        public static VexObject Load(string fileFullPathAndName)
        {
            VexObject vo;
            string    rootFolder   = Path.GetDirectoryName(fileFullPathAndName);
            string    fileNameOnly = Path.GetFileNameWithoutExtension(fileFullPathAndName);

            Environment.CurrentDirectory = rootFolder;

            string definitionsFolder = "";
            string instancesFolder   = "";
            uint   rootId            = 0;

            vo = new VexObject(fileNameOnly);

            FileStream    fs = new FileStream(fileFullPathAndName, FileMode.Open);
            XmlTextReader r  = new XmlTextReader(fs);

            r.ReadStartElement("UIL");

            while (r.Read())
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                    case "DefinitionsFolder":
                        if (r.Read())
                        {
                            definitionsFolder = r.Value.Trim();
                        }
                        break;

                    case "InstancesFolder":
                        if (r.Read())
                        {
                            instancesFolder = r.Value.Trim();
                        }
                        break;

                    case "RootId":
                        if (r.Read())
                        {
                            rootId = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                        }
                        break;
                    }
                }
            }

            fs.Close();

            string defsPath = rootFolder + Path.DirectorySeparatorChar + fileNameOnly + definitionsFolder;

            LoadDefinitions(defsPath, vo);

            string instsPath = rootFolder + Path.DirectorySeparatorChar + fileNameOnly + instancesFolder;

            LoadInstances(instsPath, vo);

            vo.Root = (Timeline)vo.Definitions[rootId];

            return(vo);
        }
Пример #30
0
        private static void LoadInstances(string folderPath, VexObject vo)
        {
            List <string> dataPaths = new List <string>();
            List <string> types     = new List <string>();

            uint instanceIdCounter = 1;

            string        libFileName = folderPath + Path.DirectorySeparatorChar + "Instances.xml";
            FileStream    fs          = new FileStream(libFileName, FileMode.Open);
            XmlTextReader r           = new XmlTextReader(fs);

            r.WhitespaceHandling = WhitespaceHandling.None;
            r.ReadStartElement("Instances");

            do
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                    case "InstanceIdCounter":
                        if (r.Read())
                        {
                            instanceIdCounter = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                            r.Read();
                        }
                        break;

                    case "InstanceItems":
                        while (r.Read())
                        {
                            if (r.IsStartElement() && r.Name == "Item")
                            {
                                dataPaths.Add(r.GetAttribute("DataPath"));
                                types.Add(r.GetAttribute("Type"));
                            }
                        }
                        break;

                    default:
                        r.Read();
                        break;
                    }
                }
            }while (r.Read());

            r.Close();
            fs.Close();

            // read actual DesignInstance Items
            for (int i = 0; i < dataPaths.Count; i++)
            {
                string    dp   = folderPath + Path.DirectorySeparatorChar + dataPaths[i];
                string    type = types[i];
                IInstance inst = LoadFromPath(type, dp);

                if (vo.Definitions.ContainsKey(inst.ParentDefinitionId))
                {
                    Timeline parent = (Timeline)vo.Definitions[inst.ParentDefinitionId];
                    parent.AddInstance(inst);
                }
            }
        }
Пример #31
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());
        }
Пример #32
0
 public bool HasSymbols(VexObject v, Timeline tl)
 {
     bool result = false;
     for (int i = 0; i < tl.Instances.Count; i++)
     {
         if (v.Definitions[tl.Instances[i].DefinitionId] is Symbol)
         {
             result = true;
             break;
         }
     }
     return result;
 }
Пример #33
0
        private static void LoadDefinitions(string folderPath, VexObject vo)
        {
            uint definitionIdCounter = 1;
            List<string> dataPaths = new List<string>();
            List<string> headerPaths = new List<string>();
            List<string> types = new List<string>();
            List<string> names = new List<string>();

            string libFileName = folderPath + Path.DirectorySeparatorChar + "Library.xml";
            FileStream fs = new FileStream(libFileName, FileMode.Open);
            XmlTextReader r = new XmlTextReader(fs);
            r.WhitespaceHandling = WhitespaceHandling.None;
            r.ReadStartElement("Library");

            do
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                        case "LibraryIdCounter":
                            if (r.Read())
                            {
                                definitionIdCounter = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                                r.Read();
                            }
                            break;

                        case "LibraryItems":
                            while (r.Read())
                            {
                                if (r.IsStartElement() && r.Name == "Item")
                                {
                                    headerPaths.Add(r.GetAttribute("HeaderPath"));
                                    dataPaths.Add(r.GetAttribute("DataPath"));
                                    types.Add(r.GetAttribute("Type"));
                                    names.Add(r.GetAttribute("Name"));
                                }
                            }
                            break;

                        default:
                            r.Read();
                            break;
                    }
                }
            }
            while (r.Read());

            r.Close();
            fs.Close();

            // read actual library Items
            for (int i = 0; i < dataPaths.Count; i++)
            {
                string dp = folderPath + Path.DirectorySeparatorChar + dataPaths[i];
                string hp = folderPath + Path.DirectorySeparatorChar + headerPaths[i];
                string type = types[i];

                IDefinition def = LoadDefinition(type, hp, dp);
                vo.Definitions.Add(def.Id, def);
                //Name = names[i];
            }
        }