コード例 #1
0
        /// <summary>
        /// Adds a new style and returns it's index.
        /// </summary>
        /// <param name="lineText"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public ushort AddStyle(LineText2D lineText, int layer)
        {
            LineText2DStyle newStyle = LineText2DStyle.From(lineText, layer);
            int             indexOf  = this.LineTextStyles.IndexOf(newStyle);

            if (indexOf < 0)
            { // the style is not found yet.
                indexOf = this.LineTextStyles.Count;
                this.LineTextStyles.Add(newStyle);
            }
            return((ushort)indexOf);
        }
コード例 #2
0
        /// <summary>
        /// Extracts style information.
        /// </summary>
        /// <param name="lineText"></param>
        /// <returns></returns>
        public static LineText2DStyle From(LineText2D lineText, int layer)
        {
            LineText2DStyle newStyle = new LineText2DStyle();

            newStyle.Color      = lineText.Color;
            newStyle.MaxZoom    = lineText.MaxZoom;
            newStyle.MinZoom    = lineText.MinZoom;
            newStyle.HaloColor  = lineText.HaloColor;
            newStyle.HaloRadius = lineText.HaloRadius;
            newStyle.Layer      = layer;
            newStyle.Size       = lineText.Size;
            return(newStyle);
        }
コード例 #3
0
        /// <summary>
        /// Determines whether the the given object is equal to the current object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is LineText2DStyle))
            { // wrong type.
                return(false);
            }
            LineText2DStyle other = (obj as LineText2DStyle);

            return(this.Layer == other.Layer &
                   this.MaxZoom == other.MaxZoom &
                   this.MinZoom == other.MinZoom &
                   this.Color == other.Color &
                   this.HaloColor == other.HaloColor &
                   this.HaloRadius == other.HaloRadius &
                   this.Layer == other.Layer &
                   this.Size == other.Size);
        }
コード例 #4
0
        /// <summary>
        /// Converts this basic entry into a scene object.
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        internal LineText2D To(LineText2DStyle style)
        {
            LineText2D lineText = new LineText2D();

            lineText.Color      = style.Color;
            lineText.HaloColor  = style.HaloColor;
            lineText.HaloRadius = style.HaloRadius;
            lineText.MaxZoom    = style.MaxZoom;
            lineText.MinZoom    = style.MinZoom;
            lineText.Size       = style.Size;

            lineText.Text = this.Text;
            lineText.X    = this.X;
            lineText.Y    = this.Y;

            lineText.MinX = int.MaxValue;
            lineText.MaxX = int.MinValue;
            for (int idx = 0; idx < lineText.X.Length; idx++)
            {
                if (lineText.X[idx] > lineText.MaxX)
                {
                    lineText.MaxX = lineText.X[idx];
                }
                if (lineText.X[idx] < lineText.MinX)
                {
                    lineText.MinX = lineText.X[idx];
                }
            }
            lineText.MinY = int.MaxValue;
            lineText.MaxY = int.MinValue;
            for (int idx = 0; idx < lineText.Y.Length; idx++)
            {
                if (lineText.Y[idx] > lineText.MaxY)
                {
                    lineText.MaxY = lineText.Y[idx];
                }
                if (lineText.Y[idx] < lineText.MinY)
                {
                    lineText.MinY = lineText.Y[idx];
                }
            }

            return(lineText);
        }
コード例 #5
0
 /// <summary>
 /// Extracts style information.
 /// </summary>
 /// <param name="lineText"></param>
 /// <returns></returns>
 public static LineText2DStyle From(LineText2D lineText, int layer)
 {
     LineText2DStyle newStyle = new LineText2DStyle();
     newStyle.Color = lineText.Color;
     newStyle.MaxZoom = lineText.MaxZoom;
     newStyle.MinZoom = lineText.MinZoom;
     newStyle.HaloColor = lineText.HaloColor;
     newStyle.HaloRadius = lineText.HaloRadius;
     newStyle.Layer = layer;
     newStyle.Size = lineText.Size;
     return newStyle;
 }
コード例 #6
0
        /// <summary>
        /// Deserializes the actual data.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override List <Scene2DEntry> DeSerialize(RuntimeTypeModel typeModel, byte[] data,
                                                           out List <BoxF2D> boxes)
        {
            // decompress if needed.
            Stream stream = null;

            if (_compress)
            {
                stream = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
            }
            else
            { // uncompressed stream.
                stream = new MemoryStream(data);
            }

            // create the memory stream.
            var collection = typeModel.Deserialize(stream, null,
                                                   typeof(PrimitivesCollection)) as PrimitivesCollection;

            if (collection == null)
            {
                throw new Exception("Could not deserialize primitives.");
            }

            // create the collection
            var primitives = new List <Scene2DEntry>();

            if (collection.Icons != null)
            {
                foreach (var primitive in collection.Icons)
                {
                    Icon2DStyle style = _styleIndex.IconStyles[primitive.StyleId];
                    Icon2D      icon  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = icon
                    });
                }
            }
            if (collection.Images != null)
            {
                foreach (var primitive in collection.Images)
                {
                    Image2DStyle style = _styleIndex.ImageStyles[primitive.StyleId];
                    Image2D      image = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = image
                    });
                }
            }
            if (collection.Lines != null)
            {
                foreach (var primitive in collection.Lines)
                {
                    Line2DStyle style = _styleIndex.LineStyles[primitive.StyleId];
                    Line2D      line  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = line
                    });
                }
            }
            if (collection.Points != null)
            {
                foreach (var primitive in collection.Points)
                {
                    Point2DStyle style = _styleIndex.PointStyles[primitive.StyleId];
                    Point2D      point = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = point
                    });
                }
            }
            if (collection.Polygons != null)
            {
                foreach (var primitive in collection.Polygons)
                {
                    Polygon2DStyle style   = _styleIndex.PolygonStyles[primitive.StyleId];
                    Polygon2D      polygon = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = polygon
                    });
                }
            }
            if (collection.Texts != null)
            {
                foreach (var primitive in collection.Texts)
                {
                    Text2DStyle style = _styleIndex.TextStyles[primitive.StyleId];
                    Text2D      text  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = text
                    });
                }
            }
            if (collection.LineTexts != null)
            {
                foreach (var primitive in collection.LineTexts)
                {
                    LineText2DStyle style    = _styleIndex.LineTextStyles[primitive.StyleId];
                    LineText2D      lineText = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = lineText
                    });
                }
            }

            // build the boxes list.
            boxes = new List <BoxF2D>();
            for (int idx = 0; idx < primitives.Count; idx++)
            {
                boxes.Add(primitives[idx].Scene2DPrimitive.GetBox());
            }
            return(primitives);
        }