Esempio n. 1
0
        private static int GetStringWidth(FigletFont font, string value)
        {
            List <int> charWidths = new List <int>();

            foreach (var character in value)
            {
                int charWidth = 0;
                for (int line = 1; line <= font.Height; line++)
                {
                    string figletCharacter = Figlet.GetCharacter(font, character, line);

                    charWidth = figletCharacter.Length > charWidth ? figletCharacter.Length : charWidth;
                }

                charWidths.Add(charWidth);
            }

            return(charWidths.Sum());
        }
Esempio n. 2
0
        public StyledString ToAscii(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            StringBuilder stringBuilder = new StringBuilder();

            int stringWidth = Figlet.GetStringWidth(this.font, value);

            char[,] characterGeometry     = new char[this.font.Height + 1, stringWidth];
            int[,] characterIndexGeometry = new int[this.font.Height + 1, stringWidth];
            Color[,] colorGeometry        = new Color[this.font.Height + 1, stringWidth];

            for (int line = 1; line <= this.font.Height; line++)
            {
                int runningWidthTotal = 0;

                for (int c = 0; c < value.Length; c++)
                {
                    char   character = value[c];
                    string fragment  = Figlet.GetCharacter(this.font, character, line);

                    stringBuilder.Append(fragment);
                    Figlet.CalculateCharacterGeometries(fragment, c, runningWidthTotal, line, characterGeometry, characterIndexGeometry);

                    runningWidthTotal += fragment.Length;
                }

                stringBuilder.AppendLine();
            }

            StyledString styledString = new StyledString(value, stringBuilder.ToString());

            styledString.CharacterGeometry      = characterGeometry;
            styledString.CharacterIndexGeometry = characterIndexGeometry;
            styledString.ColorGeometry          = colorGeometry;

            return(styledString);
        }