public SpriteFontContent(FontDescription desc)
        {
            FontName            = desc.FontName;
            Style               = desc.Style;
            FontSize            = desc.Size;
            CharacterMap        = CharacterRegion.Flatten(desc.CharacterRegions).ToList();
            VerticalLineSpacing = (int)desc.Spacing; // Will be replaced in the pipeline.
            HorizontalSpacing   = desc.Spacing;

            DefaultCharacter = desc.DefaultCharacter;
        }
示例#2
0
        public void Import(FontDescription options, string fontName)
        {
            lib = new Library();
            // Create a bunch of GDI+ objects.
            Face face = CreateFontFace(options, fontName);

            try {
                using (Brush brush = new SolidBrush(System.Drawing.Color.White))
                    using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
                        using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
                            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
                            {
                                graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                                // Which characters do we want to include?
                                var characters = CharacterRegion.Flatten(options.CharacterRegions);

                                var glyphList = new List <Glyph>();
                                // Rasterize each character in turn.
                                foreach (char character in characters)
                                {
                                    Glyph glyph = ImportGlyph(character, face, brush, stringFormat, bitmap, graphics);
                                    glyphList.Add(glyph);
                                }
                                Glyphs = glyphList;

                                // Store the font height.
                                LineSpacing = 0;
                                foreach (var glyph in Glyphs)
                                {
                                    LineSpacing = (glyph.Subrect.Height > LineSpacing) ? glyph.Subrect.Height : LineSpacing;
                                }
                            }
            } finally {
                if (face != null)
                {
                    face.Dispose();
                }
                if (lib != null)
                {
                    lib.Dispose();
                    lib = null;
                }
            }
        }
示例#3
0
        public void Import(FontDescription options, string fontName)
        {
            // Create a bunch of GDI+ objects.
            using (Font font = CreateFont(options))
                using (Brush brush = new SolidBrush(System.Drawing.Color.White))
                    using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
                        using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
                            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
                            {
                                graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                                //				var characterRegions = new List<CharacterRegion> ();
                                //				foreach (var character in options.Characters)
                                //				{
                                //					characterRegions.Add (new CharacterRegion ('a', 'b'));
                                //				}

                                // Which characters do we want to include?
                                var characters = CharacterRegion.Flatten(options.CharacterRegions);

                                var glyphList = new List <Glyph>();

                                // Rasterize each character in turn.
                                foreach (char character in characters)
                                {
                                    Glyph glyph = ImportGlyph(character, font, brush, stringFormat, bitmap, graphics);

                                    glyphList.Add(glyph);
                                }

                                Glyphs = glyphList;

                                // Store the font height.
                                LineSpacing = font.GetHeight();
                            }
        }