Show large ASCII on screen

I've written a Hexadecimal/ASCII chart, and would like to be able to show a larger version of the selected ASCII on screen. Is there a way to read the individual lines of bytes that make up a letter/symbol/number to show on screen.

1
2
3
4
5
6
7
8
9
10
|0|0|0|0|0|0|0|0| =  0   
|0|1|0|0|0|0|1|0| = 66     O    O     ( These 'O' represent ASCII 219 )
|0|0|1|0|0|1|0|0| = 36      O  O
|0|0|0|1|1|0|0|0| = 24       OO
|0|0|0|1|1|0|0|0| = 24       OO
|0|0|1|0|0|1|0|0| = 36      O  O
|0|1|0|0|0|0|1|0| = 66     O    O
|0|0|0|0|0|0|0|0| =  0

To make a large graphic X.


I'm using Microsoft 2012 Express, in the console. I don't feel comfortable yet programming in Windows mode.

Thanks for any help. And, if it can't be done, so be it.
closed account (Dy7SLyTq)
you could use pdcurses and just use window manipulation
@DTSCode

Thanks for the suggestion on PDCurses, but I've never had any luck getting any of those add on libraries to work. I've tried PDCurses, STL, SFML and probably a couple others. All I get are errors. ( Even re-tried setting up PDCurses a couple more times today, downloading the latest versions, but to no avail.. ) Given up on ever using them..
Is there a way to read the individual lines of bytes that make up a letter/symbol/number to show on screen.

You can use bitwise-and operator & with a mask to test if a bit is set, and the right-shift operator >> to update your mask.

For just an X char, you end up with

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

//|0|0|0|0|0|0|0|0| =  0   
//|0|1|0|0|0|0|1|0| = 66     O    O     ( These 'O' represent ASCII 219 )
//|0|0|1|0|0|1|0|0| = 36      O  O
//|0|0|0|1|1|0|0|0| = 24       OO
//|0|0|0|1|1|0|0|0| = 24       OO
//|0|0|1|0|0|1|0|0| = 36      O  O
//|0|1|0|0|0|0|1|0| = 66     O    O
//|0|0|0|0|0|0|0|0| =  0

int main() {
    unsigned char x_data[] = {0, 66, 36, 24, 24, 36, 66, 0};

    // for each of the slices (should really use named const rather than 8)
    for (int i = 0; i < 8; ++i) {
        cout << i << "> ";
        // mask starts with just high bit set
        unsigned char mask = 0x80;
        // loop continues until bit is shifted off end of mask
        while (mask) {
            // bit-wise and mask with current slice of letter, display
            // 'O' if bit set otherwise ' '
            cout << ((mask & x_data[i]) ? 'O' : ' ');
            // shift bit in mask one to right
            mask >>= 1;
        }
        // end slice
        cout << '\n';
    }

    return 0;
}


0>
1>  O    O
2>   O  O
3>    OO
4>    OO
5>   O  O
6>  O    O
7>


To handle strings, you'll need to output them in stripes using an extension of this approach.

You'll also need to either avoid or handle line wrapping.

Andy
Last edited on
@andywestken

Yes, that would work, if I go through all 255 ASCII codes, and make up the values for each of the 8 lines of bytes in each. But what I was hoping for, would be that when I select a character, a function can read what makes up that character, like the 'X' above', and outputs an enlarged version of it on screen, to make it easier for the user to see, than the one character shown now.
Suppose that you've got a matrix representation of the character,
define how to `enlarge' such matrix,
output the enlarged matrix.

By instance, you could simply say that each filled block translates to a bigger filled block
making
. #
. .

. . # #
. . # #
. . . .
. . . .
I suppose that it would look better if you perform an erosion
Last edited on
If you want to do this in code (bad idea), use the compiler that came with the November 2012 update (it has raw string literals). Something like this (with the Microsoft compiler the map would have to be initialized differently):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <unordered_map>

int main()
{
    std::unordered_map < int, const char* > char_map =
    {
        {
            int('A'),

             R"(
                  AA
                 AAAA
                AA  AA
               AA    AA
              AAAAAAAAAA
             AAAAAAAAAAAA
            AA          AA
           AA            AA
                            )"
        },

        {
            int('B'),

             R"(
              BBBBBBBBBB
              BB       BB
              BB       BB
              BBBBBBBBBBB
              BBBBBBBBBBB
              BB       BB
              BB       BB
              BBBBBBBBBB
                          )"
        },

        // etc.

    } ;

    std::cout << char_map['A'] << '\n' << char_map['B'] << '\n' ;
}

http://ideone.com/HevPhE

Ideally, don't do this in code; make it data driven.

Create a file with the character images (say 10 lines per character), and read it into a vector or map as part of initialization. Then, as in the above example, do a lookup to print the images. This will allow you to modify the images without having to rebuild the program, have more than one file to support different styles for the images etc.
Ooops -- I read your post a bit too simplistically.

I think the answer it that it can't be done. (That is, you cannot read the pixels of the current font.)

Or rather, it can't be done cleanly. The only way I can think to do it would be far messier than a proper GUI based solution. To start with, you'd have to draw the character offscreen and then find out what the pixels are using GetPixel or by examining the bits directly.

And the drawing the big char would be a problem. Using normal, small chars to draw the big letter would look odd as chars have a different aspect ration to pixels; drawing it directly into the console window using GDI would hit problems with screen refreshing etc. (it's not a good thing to do.)

Andy
Last edited on
> I've tried PDCurses, STL, SFML and probably a couple others. All I get are errors. (...)
> Given up on ever using them..
that's quite a shame, ¿have you considered changing your OS?
You don't need any of this stuff (PDCurses, STL, SFML etc.) to do something simple like this.

And it can be done quite cleanly and trivially.

Several dozens of FIGlet font files are available for free download; for instance this page has several of them.
http://artscene.textfiles.com/asciiart/FIGLETS/

Either use them as they are, or modify them as you please; read the characters from the file into a vector or so, and just dump the characters on stdout.
Last edited on

EDIT:: Closed this thread, as it seems there is no way to accomplish what I intended..
Last edited on
Topic archived. No new replies allowed.