Ejemplo n.º 1
0
        /// <summary>
        /// Loads a font from the ContentManager.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Font Load(IContentProvider content, string name)
        {
            var fontModel = ReadFont(content, name);

            var path = fontModel.ImagePath;

            Font result = new Font(name);

            foreach (var fontSurfaceModel in fontModel)
            {
                var image = fontSurfaceModel.Image;

                if (image.EndsWith(".png"))
                {
                    image = image.Substring(0, image.Length - 4);
                }

                var surface = content.Load <Texture2D>(Path.Combine(path, image));

                FontMetrics metrics = new FontMetrics();
                foreach (var glyph in fontSurfaceModel.Metrics)
                {
                    metrics.Add((char)glyph.Key, glyph.Value);
                }

                var fontSurface = new BitmapFontTexture(surface, metrics, name);

                result.Core.AddFontSurface(new FontSettings(fontSurfaceModel.Size, fontSurfaceModel.Style), fontSurface);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private static FontMetrics BuildFontMetrics()
        {
            var fontMetrics = new FontMetrics();

            for (int i = 0; i < 128; i++)
            {
                int col = i % 16;
                int row = i / 16;
                int x   = col * 16;
                int y   = row * 16;

                fontMetrics.Add(i, new GlyphMetrics(new Rectangle(x, y, 16, 16)));
            }

            return(fontMetrics);
        }
Ejemplo n.º 3
0
        private void ReadMetrics030(XmlNode parent)
        {
            XmlNode root = null;

            // find metrics node
            foreach (XmlNode n in parent.ChildNodes)
            {
                if (n.Name == "Metrics")
                {
                    root = n;
                    break;
                }
            }

            if (root == null)
            {
                throw new AgateResourceException(string.Format(
                                                     "Could not find Metrics node in bitmap font resource {0}.", Name));
            }

            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name != "Glyph")
                {
                    throw new AgateResourceException(string.Format(
                                                         "Expected to find glyph node, but found {0} instead.", node.Name));
                }

                GlyphMetrics glyph = new GlyphMetrics();

                char key = (char)int.Parse(node.Attributes["char"].Value);
                glyph.SourceRect = Rectangle.Parse(node.Attributes["source"].Value);

                glyph.LeftOverhang  = XmlHelper.ReadAttributeInt(node, "leftOverhang", 0);
                glyph.RightOverhang = XmlHelper.ReadAttributeInt(node, "rightOverhang", 0);

                mMetrics.Add(key, glyph);
            }
        }