Example #1
0
        public void WriteDrawObject(DrawObject drawObject)
        {
            WriteNameTable(drawObject.definitionNames, VexDrawTag.DefinitionNameTable);
            WriteNameTable(drawObject.instanceNames, VexDrawTag.InstanceNameTable);
            WriteStringTable(drawObject.paths, VexDrawTag.PathNameTable);

            WriteStrokeDefs(drawObject.strokes);
            uint fillCount = (uint)(drawObject.solidFills.Count + drawObject.gradientFills.Count);
            WriteSolidFills(drawObject.solidFills, fillCount);
            WriteGradientDefs(drawObject.gradientFills);

            for (int i = 0; i < drawObject.drawImages.Count; i++)
            {
                WriteImage(drawObject.drawImages[i]);
            }

            for (int i = 0; i < drawObject.drawSymbols.Count; i++)
            {
                WriteSymbol(drawObject.drawSymbols[i]);
            }

            for (int i = 0; i < drawObject.drawTimelines.Count; i++)
            {
                WriteTimeline(drawObject.drawTimelines[i]);
            }

            WriteBits((int)VexDrawTag.End, 8);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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();
        }
Example #5
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();
        }
Example #6
0
        private void WriteGradientDefs(List <GradientFill> gradients)
        {
            WriteTag(VexDrawTag.GradientFillList);
            WriteBits(0, 5);             // note: no nBits here, just padding
            WriteBits(gradients.Count, 11);
            for (int index = 0; index < gradients.Count; index++)
            {
                GradientFill gf = gradients[index];
                // first type - all non radial will be solid
                // use 8 bits for future expansion and to keep semi aligned
                int type = (gf.FillType == FillType.Radial) ? 1 : 0;
                WriteBits(type, 3);

                float[] tltr   = DrawObject.GetGradientLine(gf);
                int[]   values = new int[4];
                for (int i = 0; i < tltr.Length; i++)
                {
                    values[i] = (int)(tltr[i] * DrawObject.twips);
                }
                WriteFourNBitValues(values);

                // new argb colors
                List <Color> colors    = new List <Color>(gf.Fills);
                List <float> positions = new List <float>(gf.Stops);
                if (gf.FillType == FillType.Radial)
                {
                    gf.ReverseStops(colors, positions);
                }

                // stops and ratios [[col,rat],[col,rat]...]
                int stopCount = colors.Count;
                if (stopCount > 8)
                {
                    stopCount = 8;
                    Console.WriteLine("*Flash only supports 8 colors max in gradients");
                }

                uint[] wCols = new uint[stopCount];
                for (int i = 0; i < stopCount; i++)
                {
                    wCols[i] = colors[i].AFlipRGB;
                }
                uint colBits = MinBits(wCols);
                WriteNBitsCount(colBits);

                int[] ratios = new int[positions.Count];
                for (int i = 0; i < stopCount; i++)
                {
                    ratios[i] = (int)(positions[i] * 255);
                }
                uint ratioBits = MinBits(ratios);
                WriteNBitsCount(ratioBits);

                WriteBits(stopCount, 11);

                for (int i = 0; i < stopCount; i++)
                {
                    WriteBits(wCols[i], colBits);
                    WriteBits(ratios[i], ratioBits);
                }
            }
            FlushTag();
        }