/// <summary>
        /// Converts to a basic entry.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="text"></param>
        /// <param name="styleId"></param>
        /// <returns></returns>
        internal static Text2DEntry From(uint id, Text2D text, ushort styleId)
        {
            Text2DEntry entry = new Text2DEntry();

            entry.Id      = id;
            entry.Text    = text.Text;
            entry.X       = text.X;
            entry.Y       = text.Y;
            entry.StyleId = styleId;
            return(entry);
        }
        /// <summary>
        /// Serializes the actual data.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override byte[] Serialize(RuntimeTypeModel typeModel, List <Scene2DEntry> data,
                                            List <BoxF2D> boxes)
        {
            var icons     = new List <Icon2DEntry>();
            var images    = new List <Image2DEntry>();
            var lines     = new List <Line2DEntry>();
            var points    = new List <Point2DEntry>();
            var polygons  = new List <Polygon2DEntry>();
            var texts     = new List <Text2DEntry>();
            var lineTexts = new List <LineText2DEntry>();

            // build the collection object.
            var collection = new PrimitivesCollection();

            for (int idx = 0; idx < data.Count; idx++)
            {
                IScene2DPrimitive primitive = data[idx].Scene2DPrimitive;
                if (primitive is Icon2D)
                {
                    Icon2D icon = primitive as Icon2D;
                    icons.Add(Icon2DEntry.From(data[idx].Id, icon, _styleIndex.AddStyle(icon, data[idx].Layer)));
                }
                else if (primitive is Image2D)
                {
                    Image2D image = primitive as Image2D;
                    images.Add(Image2DEntry.From(data[idx].Id, image, _styleIndex.AddStyle(image, data[idx].Layer)));
                }
                else if (primitive is Line2D)
                {
                    Line2D line = primitive as Line2D;
                    lines.Add(Line2DEntry.From(data[idx].Id, line, _styleIndex.AddStyle(line, data[idx].Layer)));
                }
                else if (primitive is Point2D)
                {
                    Point2D point = primitive as Point2D;
                    points.Add(Point2DEntry.From(data[idx].Id, point, _styleIndex.AddStyle(point, data[idx].Layer)));
                }
                else if (primitive is Polygon2D)
                {
                    Polygon2D polygon = primitive as Polygon2D;
                    polygons.Add(Polygon2DEntry.From(data[idx].Id, polygon, _styleIndex.AddStyle(polygon, data[idx].Layer)));
                }
                else if (primitive is Text2D)
                {
                    Text2D text = primitive as Text2D;
                    texts.Add(Text2DEntry.From(data[idx].Id, text, _styleIndex.AddStyle(text, data[idx].Layer)));
                }
                else if (primitive is LineText2D)
                {
                    LineText2D lineText = primitive as LineText2D;
                    lineTexts.Add(LineText2DEntry.From(data[idx].Id, lineText, _styleIndex.AddStyle(lineText, data[idx].Layer)));
                }
                else
                {
                    throw new Exception("Primitive type not supported by serializer.");
                }
            }

            collection.Icons     = icons.ToArray();
            collection.Images    = images.ToArray();
            collection.Lines     = lines.ToArray();
            collection.Points    = points.ToArray();
            collection.Polygons  = polygons.ToArray();
            collection.Texts     = texts.ToArray();
            collection.LineTexts = lineTexts.ToArray();

            // create the memory stream.
            var stream = new MemoryStream();

            typeModel.Serialize(stream, collection);
            if (!_compress)
            {
                return(stream.ToArray());
            }
            return(GZipStream.CompressBuffer(stream.ToArray()));
        }