Exemple #1
0
 public bool Add(ANTBitmapChar pFTBitmapChar)
 {
     if (pFTBitmapChar.IsEmpty())
     {
         return(true);
     }
     if (IsEmpty())
     {
         if (Fits(pFTBitmapChar))
         {
             CreateBranches(pFTBitmapChar);
             pFTBitmapChar.SetXY(m_x, m_y);
             return(true);
         }
         return(false);
     }
     if (m_Leaf1.Add(pFTBitmapChar))
     {
         return(true);
     }
     if (m_Leaf2.Add(pFTBitmapChar))
     {
         return(true);
     }
     return(false);
 }
Exemple #2
0
        public void CreateAtlas()
        {
            int totalPixels = 0;

            foreach (ANTBitmapChar ch in m_BitmapChars)
            {
                totalPixels += ch.GetNumPixels();
            }

            int ixSize    = 0;
            int texWidth  = 32;
            int texHeight = 32;

            while (true)
            {
                if (totalPixels <= texWidth * texHeight)
                {
                    break;
                }
                GetNextTextureSize(ref texWidth, ref texHeight, ixSize);
                ixSize++;
            }

            m_BitmapChars.Sort(new GreaterSizeComparer());

            while (!BinPack(texWidth, texHeight))
            {
                GetNextTextureSize(ref texWidth, ref texHeight, ixSize);
                ixSize++;
            }

            byte[] pData = new byte[texWidth * texHeight];
            Array.Clear(pData, 0, pData.Length);

            foreach (ANTBitmapChar ch in m_BitmapChars)
            {
                ch.DrawToBitmap(pData, texWidth, texHeight);
                ch.ReleaseGlyph();
            }

            foreach (ANTBitmapFont font in m_BitmapFonts)
            {
                font.FinishCreating();
            }
            if (!m_UseKerning)
            {
                ReleaseLibrary();
            }

            m_Texture = pData;
            m_Bitmap  = ToBitmap(m_Texture, texWidth, texHeight);

            m_pShowAtlas = new ANTBitmapChar();
            m_pShowAtlas.SetXY(0, 0);
            m_pShowAtlas.SetSize(texWidth, texHeight);
        }