FontStuff

Avi Gupta
hackerLog
Published in
2 min readOct 14, 2018

“The only legitimate use of a computer is to play games.”

-Eugene Jarvis, creator of Defender

Unicode.

It’s the stuff that makes up all of our letters on a computer. It uses a numerical code to make a character, like the letter A. In fact, ‘A’ has a different unicode value than ‘a’. Now, ever heard of ASCII art? It uses those chars and makes it into an image. like this:

System.out.println("     |      |  ");
System.out.println(" | | ");
System.out.println(" | | ");
System.out.println(" | | ");
System.out.println(" __ __ ");
System.out.println(" \ /");
System.out.println(" \ / ");
System.out.println(" \ / ");
System.out.println(" \ / ");
System.out.println(" \ / ");
System.out.println(" \/ ");

Hence making an arrow.

We want to create a program that can take in any word and output it as a banner and output it like this:

Hello as the banner font

So what i did was I made a 5 by 7 grid.

   0 1 2 3 4
_ _ _ _ _
0 |_|_|_|_|_|
1 |_|_|_|_|_|
2 |_|_|_|_|_|
3 |_|_|_|_|_|
4 |_|_|_|_|_|
5 |_|_|_|_|_|
6 |_|_|_|_|_|

Turning bits on/off can give us letters. That means that each row is a 5-bit integer and each letter is a 7-element array of 5-bit integers.

This is the code for the letter A:

public static final Letter A = new Letter ('A', new int[]{14, 17, 17, 31, 17, 17,17});

But when it was first run, the letters were on top of one another, not side by side. So for a given string, we have to take all of the letters and go row by row for all of them. So we added this function to fix that problem:

public String getRow(int row) {
int i = spec[row];
char[] line = new char[6];
for (int j = 0; j < 5; j++) {
line[j] = (((i >> j) & 1) == 0 ? ' ': letterType);
}
line[5] = ' ';
return new String(line);
}

(spec means a specification. )

This makes each individual row of each letter into one single row, doing the same for each of the seven rows.

See the full code on gitHub here.

Have a little fun with this on IntelliJ IDEA Community Edition.

Signing out ‘till next time,

Avi

--

--

Avi Gupta
hackerLog

Named after the first 2 games I got on my xBox, Forza and Minecraft. Also, i have a blog. Real name is Avi.