Exemplo n.º 1
0
 public bool GetRectByCodePoint(int codepoint, out TextureFontGlyphData glyphdata)
 {
     if (!codePointLocations.TryGetValue(codepoint, out glyphdata))
     {
         glyphdata = null;
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
        //read font info from xml document
        public SimpleFontAtlas LoadFontInfo(string filename)
        {
            SimpleFontAtlas simpleFontAtlas = new Fonts.SimpleFontAtlas();
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(filename);
            //read
            int total_W = 0;
            int total_H = 0;
            {

                foreach (XmlElement xmlelem in xmldoc.GetElementsByTagName("total_img"))
                {
                    simpleFontAtlas.Width = total_W = int.Parse(xmlelem.GetAttribute("w"));
                    simpleFontAtlas.Height = total_H = int.Parse(xmlelem.GetAttribute("h"));
                    //only 1...

                    break;
                }
            }
            foreach (XmlElement glyphElem in xmldoc.GetElementsByTagName("glyph"))
            {
                //read
                string unicodeHex = glyphElem.GetAttribute("uc");
                int codepoint = int.Parse(glyphElem.GetAttribute("c"));
                char c = (char)int.Parse(unicodeHex.Substring(2), System.Globalization.NumberStyles.HexNumber);
                Rectangle area = ParseRect(glyphElem.GetAttribute("ltwh"));
                var glyphData = new TextureFontGlyphData();
                area.Y += area.Height;//*** 
                glyphData.Rect = area;
                float[] borderXY = ParseFloatArray(glyphElem.GetAttribute("borderXY"));
                float[] matrix = ParseFloatArray(glyphElem.GetAttribute("mat"));

                glyphData.BorderX = borderXY[0];
                glyphData.BorderY = borderXY[1];

                glyphData.AdvanceX = matrix[0];
                glyphData.AdvanceY = matrix[1];
                glyphData.BBoxXMin = matrix[2];
                glyphData.BBoxXMax = matrix[3];
                glyphData.BBoxYMin = matrix[4];
                glyphData.BBoxYMax = matrix[5];
                glyphData.ImgWidth = matrix[6];
                glyphData.ImgHeight = matrix[7];
                glyphData.HAdvance = matrix[8];
                glyphData.HBearingX = matrix[9];
                glyphData.HBearingY = matrix[10];
                glyphData.VAdvance = matrix[11];
                glyphData.VBearingX = matrix[12];
                glyphData.VBearingY = matrix[13];
                //--------------- 
                simpleFontAtlas.AddGlyph(codepoint, glyphData);                 
            }
            return simpleFontAtlas;
        }
Exemplo n.º 3
0
 public void AddGlyph(int codePoint, TextureFontGlyphData glyphData)
 {
     codePointLocations.Add(codePoint, glyphData);
 }