Exemplo n.º 1
0
        /// <summary>
        /// Compiles the specified font description into a <see cref="SignedDistanceFieldSpriteFont" /> object.
        /// </summary>
        /// <param name="fontFactory">The font factory used to create the fonts</param>
        /// <param name="fontAsset">The font description.</param>
        /// <returns>A SpriteFontData object.</returns>
        public static Graphics.SpriteFont Compile(IFontFactory fontFactory, SpriteFontAsset fontAsset)
        {
            if (fontAsset.FontType != SpriteFontType.SDF)
            {
                throw new ArgumentException("Tried to compile an incompatible sprite font with compiler for scalable fonts");
            }

            float lineSpacing;
            float baseLine;

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

            Bitmap bitmap = GlyphPacker.ArrangeGlyphs(glyphs);

            return(SignedDistanceFieldFontWriter.CreateSpriteFontData(fontFactory, fontAsset, glyphs, lineSpacing, baseLine, bitmap));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compiles the specified font description into a <see cref="OfflineRasterizedSpriteFont" /> 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)
        {
            var fontTypeStatic = fontAsset.FontType as OfflineRasterizedSpriteFontType;

            if (fontTypeStatic == null)
            {
                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.FontType.IsPremultiplied)
            {
                if (fontAsset.FontType.AntiAlias == FontAntiAliasMode.ClearType)
                {
                    BitmapUtils.PremultiplyAlphaClearType(bitmap, srgb);
                }
                else
                {
                    BitmapUtils.PremultiplyAlpha(bitmap, srgb);
                }
            }

            return(OfflineRasterizedSpriteFontWriter.CreateSpriteFontData(fontFactory, fontAsset, glyphs, lineSpacing, baseLine, bitmap, srgb));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compiles the specified font description into a <see cref="SignedDistanceFieldSpriteFont" /> object.
        /// </summary>
        /// <param name="fontFactory">The font factory used to create the fonts</param>
        /// <param name="fontAsset">The font description.</param>
        /// <returns>A SpriteFontData object.</returns>
        public static Graphics.SpriteFont Compile(IFontFactory fontFactory, SpriteFontAsset fontAsset)
        {
            var fontTypeSDF = fontAsset.FontType as SignedDistanceFieldSpriteFontType;

            if (fontTypeSDF == null)
            {
                throw new ArgumentException("Tried to compile a dynamic sprite font with compiler for signed distance field fonts");
            }

            float lineSpacing;
            float baseLine;

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

            Bitmap bitmap = GlyphPacker.ArrangeGlyphs(glyphs);

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