Ejemplo n.º 1
0
        public void Import(CommandLineOptions options)
        {
            // Create a bunch of GDI+ objects.
            using (Font font = CreateFont(options))
                using (Brush brush = new SolidBrush(Color.White))
                    using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
                        using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
                            using (Graphics graphics = Graphics.FromImage(bitmap))
                            {
                                graphics.PixelOffsetMode   = options.Sharp ? PixelOffsetMode.None : 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, font, brush, stringFormat, bitmap, graphics);

                                    glyphList.Add(glyph);
                                }

                                Glyphs = glyphList;

                                // Store the font height.
                                LineSpacing = font.GetHeight();
                            }
        }
Ejemplo n.º 2
0
        public void Import(CommandLineOptions options)
        {
            // Create a bunch of GDI+ objects.
            using (Font font = CreateFont(options))
                using (Brush brush = new SolidBrush(Color.White))
                    using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
                        using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
                            using (Graphics graphics = Graphics.FromImage(bitmap))
                            {
                                graphics.PixelOffsetMode   = options.Sharp ? PixelOffsetMode.None : 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.
                                int count = 0;

                                foreach (char character in characters)
                                {
                                    ++count;

                                    if (count == 500)
                                    {
                                        Console.WriteLine("WARNING: capturing a large font. This may take a long time to complete and could result in too large a texture. Consider using a smaller set of character regions.");
                                        Console.Write(".");
                                    }
                                    else if ((count % 500) == 0)
                                    {
                                        Console.Write(".");
                                    }
                                    Glyph glyph = null;
                                    if (options.GenerateDistance)
                                    {
                                        glyph = ImportGlyph(character, font, brush, stringFormat, bitmap, graphics, options.Downscale);
                                        GenerateDistances(glyph, options.Downscale, options.Spread, options.DistanceColor);
                                    }
                                    else
                                    {
                                        glyph = ImportGlyph(character, font, brush, stringFormat, bitmap, graphics);
                                    }
                                    glyphList.Add(glyph);
                                }

                                if (count > 500)
                                {
                                    Console.WriteLine();
                                }

                                Glyphs = glyphList;

                                // Store the font height.
                                LineSpacing = font.GetHeight();
                            }
        }
Ejemplo n.º 3
0
        public void Import(CommandLineOptions options)
        {
            // Load the source bitmap.
            Bitmap bitmap;

            try
            {
                bitmap = new Bitmap(options.SourceFont);
            }
            catch
            {
                throw new Exception(string.Format("Unable to load '{0}'.", options.SourceFont));
            }

            // Convert to our desired pixel format.
            bitmap = BitmapUtils.ChangePixelFormat(bitmap, PixelFormat.Format32bppArgb);

            // What characters are included in this font?
            var  characters       = CharacterRegion.Flatten(options.CharacterRegions).ToArray();
            int  characterIndex   = 0;
            char currentCharacter = '\0';

            // Split the source image into a list of individual glyphs.
            var glyphList = new List <Glyph>();

            Glyphs      = glyphList;
            LineSpacing = 0;

            foreach (Rectangle rectangle in FindGlyphs(bitmap))
            {
                if (characterIndex < characters.Length)
                {
                    currentCharacter = characters[characterIndex++];
                }
                else
                {
                    currentCharacter++;
                }

                glyphList.Add(new Glyph(currentCharacter, bitmap, rectangle));

                LineSpacing = Math.Max(LineSpacing, rectangle.Height);
            }

            // If the bitmap doesn't already have an alpha channel, create one now.
            if (BitmapUtils.IsAlphaEntirely(255, bitmap))
            {
                BitmapUtils.ConvertGreyToAlpha(bitmap);
            }
        }