Пример #1
0
        /// <summary>
        /// Compiles the specified font description into a <see cref="StaticSpriteFont" /> object.
        /// </summary>
        /// <param name="fontFactory">The font factory used to create the fonts</param>
        /// <param name="fontAsset">The font description.</param>
        /// <param name="srgb"></param>
        /// <returns>A SpriteFontData object.</returns>
        public static Graphics.SpriteFont Compile(IFontFactory fontFactory, SpriteFontAsset fontAsset, bool srgb)
        {
            if (fontAsset.IsDynamic)
            {
                throw new ArgumentException("Tried to compile a dynamic sprite font with compiler for static fonts");
            }

            float lineSpacing;
            float baseLine;

            var glyphs = ImportFont(fontAsset, out lineSpacing, out baseLine);

            // Optimize.
            foreach (Glyph glyph in glyphs)
            {
                GlyphCropper.Crop(glyph);
            }

            Bitmap bitmap = GlyphPacker.ArrangeGlyphs(glyphs);

            // Automatically detect whether this is a monochromatic or color font?
            //if (fontAsset.Format == FontTextureFormat.Auto)
            //{
            //    bool isMono = BitmapUtils.IsRgbEntirely(Color.White, bitmap);
            //
            //    fontAsset.Format = isMono ? FontTextureFormat.CompressedMono :
            //                                     FontTextureFormat.Rgba32;
            //}

            // Convert to pre-multiplied alpha format.
            if (!fontAsset.NoPremultiply)
            {
                if (fontAsset.AntiAlias == FontAntiAliasMode.ClearType)
                {
                    BitmapUtils.PremultiplyAlphaClearType(bitmap, srgb);
                }
                else
                {
                    BitmapUtils.PremultiplyAlpha(bitmap, srgb);
                }
            }

            return(StaticSpriteFontWriter.CreateSpriteFontData(fontFactory, fontAsset, glyphs, lineSpacing, baseLine, bitmap, srgb));
        }
Пример #2
0
        /// <summary>
        /// Compiles the specified font description into a <see cref="SpriteFontData" /> object.
        /// </summary>
        /// <param name="fontAsset">The font description.</param>
        /// <returns>A SpriteFontData object.</returns>
        public static StaticSpriteFontData Compile(SpriteFontAsset fontAsset)
        {
            float lineSpacing;
            float baseLine;

            Glyph[] glyphs = ImportFont(fontAsset, out lineSpacing, out baseLine);

            // Optimize.
            foreach (Glyph glyph in glyphs)
            {
                GlyphCropper.Crop(glyph);
            }

            Bitmap bitmap = GlyphPacker.ArrangeGlyphs(glyphs);

            // Automatically detect whether this is a monochromatic or color font?
            //if (fontAsset.Format == FontTextureFormat.Auto)
            //{
            //    bool isMono = BitmapUtils.IsRgbEntirely(Color.White, bitmap);
            //
            //    fontAsset.Format = isMono ? FontTextureFormat.CompressedMono :
            //                                     FontTextureFormat.Rgba32;
            //}

            // Convert to premultiplied alpha format.
            if (!fontAsset.NoPremultiply)
            {
                if (fontAsset.AntiAlias == FontAntiAliasMode.ClearType)
                {
                    BitmapUtils.PremultiplyAlphaClearType(bitmap);
                }
                else
                {
                    BitmapUtils.PremultiplyAlpha(bitmap);
                }
            }

            return(SpriteFontWriter.CreateSpriteFontData(fontAsset, glyphs, lineSpacing, baseLine, bitmap));
        }