示例#1
0
 public GameFontSystem(IServiceRegistry registry)
     : base(registry)
 {
     Visible = true;
     FontSystem = new FontSystem();
     Services.AddService(typeof(FontSystem), FontSystem);
     Services.AddService(typeof(IFontFactory), FontSystem);
 }
示例#2
0
        public FontCacheManager(FontSystem system, int textureDefaultSize = 1024)
        {
            this.system = system;
            Textures = cacheTextures;

            // create the cache textures
            var newTexture = Texture.New2D(system.GraphicsDevice, textureDefaultSize, textureDefaultSize, PixelFormat.R8_UNorm);
            cacheTextures.Add(newTexture);
            newTexture.Reload = ReloadCache;
            ClearCache();
        }
示例#3
0
        public StaticSpriteFont(FontSystem fontSystem, StaticSpriteFontData spriteFontData)
            : base(fontSystem, spriteFontData, false)
        {
            characterToGlyph = new Dictionary <char, Glyph>(spriteFontData.Glyphs.Length);

            // build the character map
            foreach (var glyph in spriteFontData.Glyphs)
            {
                var character = (char)glyph.Character;
                characterToGlyph[character] = glyph;
            }

            // Prepare kernings if they are available.
            var kernings = spriteFontData.Kernings;

            if (kernings != null)
            {
                for (int i = 0; i < kernings.Length; i++)
                {
                    int key = (kernings[i].First << 16) | kernings[i].Second;
                    KerningMap.Add(key, kernings[i].Offset);
                }
            }

            // Read the texture data.
            StaticTextures = new Texture2D[spriteFontData.Bitmaps.Length];
            for (int i = 0; i < StaticTextures.Length; i++)
            {
                if (spriteFontData.Bitmaps[i].Value != null)
                {
                    StaticTextures[i] = Texture2D.New(fontSystem.GraphicsDevice, spriteFontData.Bitmaps[i].Value).DisposeBy(this);
                }
            }
            Textures = StaticTextures;

            BaseOffsetY        = spriteFontData.BaseOffset;
            DefaultLineSpacing = spriteFontData.FontDefaultLineSpacing;
        }
示例#4
0
        public DynamicSpriteFont(FontSystem fontSystem, DynamicSpriteFontData fontData)
            : base(fontSystem, fontData, true)
        {
            // import font properties from font data
            style      = fontData.Style;
            fontName   = fontData.FontName;
            useKerning = fontData.UseKerning;
            antiAlias  = fontData.AntiAlias;

            // retrieve needed info from the font
            float relativeLineSpacing;
            float relativeBaseOffsetY;
            float relativeMaxWidth;
            float relativeMaxHeight;

            FontManager.GetFontInfo(fontData.FontName, fontData.Style, out relativeLineSpacing, out relativeBaseOffsetY, out relativeMaxWidth, out relativeMaxHeight);

            // set required base properties
            DefaultLineSpacing = relativeLineSpacing * Size;
            BaseOffsetY        = relativeBaseOffsetY * Size;
            Textures           = FontCacheManager.Textures;
            Swizzle            = SwizzleMode.RRRR;
        }