예제 #1
0
 /// <summary>
 /// Function to create the root node.
 /// </summary>
 /// <param name="imageSize">Size of the image.</param>
 public static void CreateRoot(Size imageSize)
 {
     Root = new GlyphNode(null)
     {
         Region = new Rectangle(0, 0, imageSize.Width, imageSize.Height)
     };
 }
예제 #2
0
        /// <summary>
        /// Function to add a node as a child to this node.
        /// </summary>
        /// <param name="dimensions">Dimensions that the node will occupy.</param>
        public GlyphNode AddNode(Size dimensions)
        {
            if (!IsLeaf)
            {
                GlyphNode node = Left.AddNode(dimensions);
                // If we can't add the node to the left, then try the right.
                return(node ?? Right.AddNode(dimensions));
            }

            // Do nothing if there's no more room.
            if (_noMoreRoom)
            {
                return(null);
            }

            // Ensure we can fit this node.
            if ((dimensions.Width > Region.Width) || (dimensions.Height > Region.Height))
            {
                return(null);
            }

            // We have an exact fit, so there will be no more room for other nodes.
            if ((dimensions.Width == Region.Width) && (dimensions.Height == Region.Height))
            {
                _noMoreRoom = true;
                return(this);
            }

            Left  = new GlyphNode(this);
            Right = new GlyphNode(this);

            // Subdivide.
            var delta = new Size(Region.Width - dimensions.Width, Region.Height - dimensions.Height);

            if (delta.Width > delta.Height)
            {
                Left.Region  = new Rectangle(Region.Left, Region.Top, dimensions.Width, Region.Height);
                Right.Region = new Rectangle(Region.Left + dimensions.Width, Region.Top, delta.Width, Region.Height);
            }
            else
            {
                Left.Region  = new Rectangle(Region.Left, Region.Top, Region.Width, dimensions.Height);
                Right.Region = new Rectangle(Region.Left, Region.Top + dimensions.Height, Region.Width, delta.Height);
            }

            return(Left.AddNode(dimensions));
        }
예제 #3
0
        /// <summary>
        /// Function to add a node to the
        /// </summary>
        /// <param name="dimensions">The glyph dimensions.</param>
        /// <returns>A rectangle for the area on the image that the glyph will be located at.  NULL if there's no room.</returns>
        public static Rectangle?Add(Size dimensions)
        {
            if ((dimensions.Width > Root.Region.Width) || (dimensions.Height > Root.Region.Height))
            {
                throw new ArgumentOutOfRangeException("dimensions", Resources.GORGFX_FONT_GLYPH_NODE_TOO_LARGE);
            }

            // Do nothing here.
            if ((dimensions.Width == 0) || (dimensions.Height == 0))
            {
                return(Rectangle.Empty);
            }

            GlyphNode newNode = Root.AddNode(dimensions);

            if (newNode == null)
            {
                return(null);
            }

            return(newNode.Region);
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GlyphNode"/> class.
 /// </summary>
 /// <param name="parentNode">The parent node.</param>
 public GlyphNode(GlyphNode parentNode)
 {
     Region = Rectangle.Empty;
     Parent = parentNode;
 }