Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
 private void DrawSymbol(Vex.Symbol symbol)
 {
     for (int i = 0; i < symbol.Shapes.Count; i++)
     {
         Vex.Shape sh = symbol.Shapes[i];
         DrawShape(sh);
     }
 }
Ejemplo n.º 3
0
        public DrawSymbol(Symbol symbol)
        {
            Id = symbol.Id;
            ExportName = symbol.Name;
            StrokeBounds = symbol.StrokeBounds;

            ParseShapes(symbol.Shapes);
        }
Ejemplo n.º 4
0
 private void DrawFilteredSymbol(Vex.Symbol sy)
 {
     foreach (Vex.Shape sh in sy.Shapes)
     {
         if (!sh.IsV2DShape())
         {
             DrawShape(sh);
         }
     }
 }
Ejemplo n.º 5
0
        public void AddShape(string name, Symbol sy, Matrix m)
        {
            foreach (Shape sh in sy.Shapes)
            {
                if (sh.IsV2DShape())
                {
                    Shapes.Add(new PolygonShape2D(name, sh, m));
                }

            }
        }
Ejemplo n.º 6
0
		public abstract void WriteSymbolDefinition(Symbol symbol);
Ejemplo n.º 7
0
 private void DrawSymbol(Symbol symbol)
 {
     for (int i = 0; i < symbol.Shapes.Count; i++)
     {
         Shape sh = symbol.Shapes[i];
         DrawShape(sh);
     }
 }
Ejemplo n.º 8
0
 private void DrawFilteredSymbol(Symbol sy)
 {
     foreach (Shape sh in sy.Shapes)
     {
         if (!sh.IsV2DShape())
         {
             DrawShape(sh);
         }
     }
 }
Ejemplo n.º 9
0
 public void Render(Symbol symbol, Graphics g)
 {
     this.g = g;
     translateMatrix = new System.Drawing.Drawing2D.Matrix();
     DrawSymbol(symbol);
     translateMatrix.Dispose();
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public override void WriteSymbolDefinition(Symbol symbol)
 {
     for (int i = 0; i < symbol.Shapes.Count; i++)
     {
         Shape sh = symbol.Shapes[i];
         RenderPath(sh.Fill, sh.Stroke, sh.ShapeData, true);
     }
 }
Ejemplo n.º 12
0
        public override void WriteSymbolDefinition(Symbol symbol)
        {
            string defName = GetDefinitionName(symbol);

            xw.OpenSymbolDefTag(defName, (int)symbol.StrokeBounds.Size.Width, (int)symbol.StrokeBounds.Size.Height);
            for (int i = 0; i < symbol.Shapes.Count; i++)
            {
                Shape sh = symbol.Shapes[i];
                RenderPath(sh.Fill, sh.Stroke, sh.ShapeData, false);
            }
            xw.CloseSymbolDefTag();

            xw.WriteVisualBrushRef(visualBrushPrefix + symbol.Id.ToString(), defName);
        }
Ejemplo n.º 13
0
        private static void ConsolidatePaths(Symbol symbol, DVexWriter writer)
        {
            List<FillStyle> fills = new List<FillStyle>();
            List<StrokeStyle> strokes = new List<StrokeStyle>();
            fills.Add( new SolidFill(Color.Transparent) );
            strokes.Add( new SolidStroke(0.0F, Color.Transparent) );
            ArrayList allPaths = new ArrayList();
            ArrayList allSrs = new ArrayList();

            // Find all used colors/strokes, and the F0,F1,S info for each seg
            foreach(Shape sh in symbol.Shapes)
            {
                foreach(IShapeData s in sh.ShapeData)
                {
                    int fill = 0;
                    int stroke = 0;
                    if (!fills.Contains(shape.Fills[s.FillIndex]))
                    {
                        fill = fills.Add(shape.Fills[s.FillIndex]);
                    }
                    else
                    {
                        fill = fills.IndexOf(shape.Fills[s.FillIndex]);
                    }
                    if( !strokes.Contains(shape.Strokes[s.StrokeIndex]) )
                    {
                        stroke = strokes.Add(shape.Strokes[s.StrokeIndex]);
                    }
                    else
                    {
                        stroke = strokes.IndexOf(shape.Strokes[s.StrokeIndex]);
                    }
                    // break path into shape records
                    foreach(IPathPrimitive ipp in s.Path)
                    {
                        if(ipp is IShapeData)
                        {
                            IShapeData ip = (IShapeData)ipp;
                            if(allPaths.Contains(ip))
                            {
                                // this must be a fill1 if it is a dup
                                int index = allPaths.IndexOf(ip);
                                Shrec sr = (Shrec)allSrs[index];
                                Shrec newShrec = new Shrec(0, 0);
                                newShrec.F0 = (sr.F0 == 0) ? fill : sr.F0 ;
                                newShrec.F1 = (sr.F1 == 0) ? fill : sr.F1 ;
                                newShrec.S = (sr.S == 0) ? stroke : sr.S ;
                                allSrs[index] = newShrec;
                            }
                            else
                            {
                                allSrs.Add(new Shrec(fill, stroke));
                                allPaths.Add(ip);
                            }
                        }
                    }
                } // end groups
            } // end shapes

            // ok, now write out colors
            // sort fills by rgb, argb, and gradients
            ArrayList orderedFills = new ArrayList();
            ArrayList rgbas = new ArrayList();
            ArrayList gfs = new ArrayList();
            foreach(Fill sf in fills)
            {
                if(sf is SolidFill)
                {
                    if( ((SolidFill)sf).Color.A == 255 ||
                        (SolidFill)sf == fills[0]) // 'no fill'
                    {
                        orderedFills.Add(sf);
                    }
                    else
                    {
                        rgbas.Add(sf);
                    }
                }
                else if(sf is GradientFill)
                {
                    gfs.Add(sf);
                }
                else
                {
                    // bitmap fills
                    orderedFills.Add(new SolidFill(Color.Gray));
                };
            }

            SolidFill[] wrgbs = new SolidFill[orderedFills.Count];
            wrgbs[0] = new SolidFill(Color.FromArgb(255,0,0,0));
            int fRgb = 1;
            foreach(Fill f in orderedFills)
            {
                if(f != fills[0])
                {
                    wrgbs[fRgb++] = (SolidFill)f;
                }
            }
            int fRgba = 0;
            SolidFill[] wrgbas = new SolidFill[rgbas.Count];
            foreach(Fill f in rgbas)
            {
                orderedFills.Add(f);
                wrgbas[fRgba++] = (SolidFill)f;
            }

            int fGr = 0;
            GradientFill[] wgfs = new GradientFill[gfs.Count];
            foreach(Fill f in gfs)
            {
                orderedFills.Add(f);
                wgfs[fGr++] = (GradientFill)(f);
            }

            writer.WriteNbitColorDefs(wrgbs);
            writer.WriteNbitColorDefs(wrgbas);
            writer.WriteNbitGradientDefs(wgfs);
            //writer.WriteRgbColorDefs(wrgbs);
            //writer.WriteRgbaColorDefs(wrgbas);
            //writer.WriteGradientColorDefs(wgfs);

            // ok, colors written, now strokes
            // write out all the stroke defs second
            // get counts
            int wrgbCount = 0;
            int wrgbaCount = 0;
            foreach(Stroke st in strokes)
            {
                if(st.Color.A == 255 || st == strokes[0])
                    {wrgbCount++;}
                    else{wrgbaCount++;}
            }
            // create stroke arrays
            Stroke[] wsrgbs = new Stroke[wrgbCount];
            Stroke[] wsrgbas = new Stroke[wrgbaCount];
            int sRgb = 0;
            int sRgba = 0;
            foreach(Stroke st in strokes)
            {
                if( st.Color.A == 255 || st == strokes[0])
                {
                    wsrgbs[sRgb++] = st;
                }
                else
                {
                    wsrgbas[sRgba++] = st;
                }
            }
            // now write the stroke data
            writer.WriteNbitStrokeDefs(wsrgbs);
            writer.WriteNbitStrokeDefs(wsrgbas);
            //writer.WriteRgbStrokeDefs(wsrgbs);
            //writer.WriteRgbaStrokeDefs(wsrgbas);

            // and now paths
            // valid pathsegs must have the same F0, F1, and S
            ArrayList tempPaths = new ArrayList();
            ArrayList tempSrsAl = new ArrayList();
            PathCollection pc = new PathCollection();
            Shrec curShrec = Shrec.Empty;
            for(int i = 0; i < allSrs.Count; i++) //Shrec sr in srsAl)
            {
                Shrec sr = (Shrec)allSrs[i];
                if(sr.Equals(curShrec) || curShrec.Equals(Shrec.Empty))
                {
                    //add to path
                    pc.Add((IShapeData)allPaths[i]);
                }
                else
                {
                    // write to hash
                    tempPaths.Add(pc);
                    tempSrsAl.Add(curShrec);

                    pc = new PathCollection();
                    pc.Add((IShapeData)allPaths[i]);
                }
                curShrec = sr;
            }
            if(!tempSrsAl.Contains(curShrec))
            {
                tempPaths.Add(pc);
                tempSrsAl.Add(curShrec);
            }
            // split non contig paths
            ArrayList paths = new ArrayList();
            ArrayList srsAl = new ArrayList();
            foreach(PathCollection pcoll in tempPaths)
            {
                //pcoll.ReorderPath();
                PathCollection[] pcolls = pcoll.SplitPath();
                foreach(PathCollection splitP in pcolls)
                {
                    paths.Add(splitP);
                    srsAl.Add(tempSrsAl[tempPaths.IndexOf(pcoll)] );
                    //writer.WritePath(splitP.PointSegments);
                }
            }
            IShapeData[][] ips = new IShapeData[paths.Count][];
            for(int i = 0; i < paths.Count; i++)
            {
                ips[i] = ((PathCollection)paths[i]).PointSegments;
            }
            writer.WritePaths(ips);

            // convert to array
            Shrec[] srs = new Shrec[srsAl.Count];
            for(int i = 0; i < srsAl.Count; i++)
            {
                srs[i] = (Shrec)srsAl[i];
            }

            // and finally, uses - must be sorted by fill color
            // use order Fill1 (no strokes), fill0[stroke], stroke only's
            // for each fill index{..}, then dangling strokes

            ArrayList shapeRecords = new ArrayList();

            // start at 1 to avoid empty fills
            foreach(Fill f in orderedFills)
            {
                int curFill = fills.IndexOf(f);
                if(curFill != 0)
                {
                    // all F1's of this color first
                    ArrayList Fs = new ArrayList();
                    for(int i = 0; i < srs.Length; i++)
                    {
                        if(srs[i].F0 == curFill)
                        {
                            // add use for F0
                            ShapeRecord curSr = new ShapeRecord();

                            curSr.Fill = orderedFills.IndexOf(f);
                            curSr.Stroke = srs[i].S;
                            curSr.Path = i;
                            Fs.Add(curSr);
                        }
                        if(srs[i].F1 == curFill )
                        {
                            // add use for F1
                            ShapeRecord curSr = new ShapeRecord();
                            curSr.Fill = orderedFills.IndexOf(f);
                            curSr.Stroke = 0;
                            curSr.Path = i;
                            Fs.Add(curSr);
                        }
                    }
                    //now sort the F1s from tip to tail
                    if(Fs.Count > 0)
                    {
                        ArrayList finalFs = new ArrayList();
                        finalFs.Add(Fs[0]);
                        PointF end =
                            ((PathCollection)paths[((ShapeRecord)Fs[0]).Path]).LastPoint;
                        Fs.RemoveAt(0);
                        while(Fs.Count > 0)
                        {
                            bool found = false;
                            foreach(ShapeRecord sr in Fs)
                            {
                                PathCollection srp = (PathCollection)paths[sr.Path];
                                if(srp.FirstPoint == end)
                                {
                                    end = srp.LastPoint;
                                    finalFs.Add(sr);
                                    Fs.Remove(sr);
                                    found = true;
                                    break;
                                }
                            }
                            if(found == false)
                            {
                                finalFs.Add(Fs[0]);
                                end = ( (PathCollection)paths[
                                    ((ShapeRecord)Fs[0]).Path] ).LastPoint;
                                Fs.RemoveAt(0);
                            }
                        }
                        // and write them
                        foreach(ShapeRecord sr in finalFs)
                        {
                            shapeRecords.Add(sr);
                        }
                    }

                }
            }
            for(int i = 0; i < srs.Length; i++)
            {
                if(srs[i].F0 == 0 && srs[i].F1 == 0)
                {
                    // must be stroke
                    ShapeRecord curSr = new ShapeRecord();
                    curSr.Fill = 0;
                    curSr.Stroke = srs[i].S;
                    curSr.Path = i;
                    shapeRecords.Add(curSr);
                }
            }
            // convert to array
            ShapeRecord[] srecs = new ShapeRecord[shapeRecords.Count];
            for(int i = 0; i < shapeRecords.Count; i++)
            {
                srecs[i] = (ShapeRecord)shapeRecords[i];
            }

            writer.WriteUses(srecs);
        }
Ejemplo n.º 14
0
 public static string ShapeToAsDraw(Symbol symbol, string filename)
 {
     DVexWriter	writer				= new DVexWriter();
     ConsolidatePaths(symbol, writer);
     return writer.Results.ToString();
 }
Ejemplo n.º 15
0
 public static string ShapeToAsDraw(Symbol symbol)
 {
     string s = ShapeToAsDraw(symbol, "");
     return s;
 }
Ejemplo n.º 16
0
		private void ParseDefineShape4Tag(DefineShape4Tag tag)
		{
			curSymbol = new Symbol(v.NextId());

			curSymbol.Bounds = ParseRect(tag.EdgeBounds);
			curSymbol.StrokeBounds = ParseRect(tag.ShapeBounds);
			curSymbol.Id = tag.ShapeId;
			v.Definitions.Add(curSymbol.Id, curSymbol);

			ParseShapeWithStyle(tag.Shapes);
		}