So I threw together a mildly cleaned up version and some test code:
it's pretty rough in some ways, but does wordwrap and stuff in a way not entirely differently than normal fonts in processing...
Code:/*
the basic idea is you have characters made up of
-----
|\|/|
-- --
|/|\|
-----
*
the patterns for each stored in a hashmap of arrays,
keyed on the letter, value is an array of which segments
to display, numbered thus:
----1----
|\ | / |
2 3 4 5 6
--7-- -8--
9 10 11 12 13
| / | \ |
----14----
0
*/
HashMap font = new HashMap();
void setup(){
size(250,250);
setupFont();
strokeWeight(2);
drawText("the quick brown fox 'jumps' over the lazy dog?!... - 0 1 2 3 4 5 6 7 8 9 ",10,10,200,8,16);
}
void drawText(String s,float x, float y, float maxwidth ,float w, float h){
float origx =x ;
s = s.toUpperCase();
String[] words = s.split(" ");
for(int wordptr = 0; wordptr < words.length; wordptr++){
String word = words[wordptr];
if(x + word.length()*w > origx+maxwidth){
x = origx;
y += h * 1.5;
}
for(int i = 0; i < word.length();i++){
drawChar(word.substring(i,i+1),x,y,w-3,h);
x += w;
}
x += w;
}
}
void setupFont(){
font.put("0",new int[] {1,2,5,6,9,10,13,14});
font.put("1",new int[] {4,11} );
font.put("2",new int[] {1,6,8,7,9,14} );
font.put("3",new int[] {1,6,8,7,13,14} );
font.put("4",new int[] {2,7,8,6,13} );
font.put("5",new int[] {1,2,7,8,13,14} );
font.put("6",new int[] {1,2,7,8,13,14,9} );
font.put("7",new int[] {1,6,13} );
font.put("8",new int[] {1,2,6,7,8,9,13,14} );
font.put("9",new int[] {1,2,6,7,8,13,14} );
font.put("A",new int[] {9,2,1,6,13,7,8} );
font.put("B",new int[] {1,14,4,6,11,13,8} );
font.put("C",new int[] {1,2,9,14} );
font.put("D",new int[] {1,14,4,11,6,13} );
font.put("E",new int[] {1,2,7,9,14} );
font.put("F",new int[] {1,2,7,9} );
font.put("G",new int[] {1,2,9,14,13,8} );
font.put("H",new int[] {2,9,6,13,7,8} );
font.put("I",new int[] {1,4,11,14} );
font.put("J",new int[] {9,14,13,6} );
font.put("K",new int[] {2,9,7,5,12} );
font.put("L",new int[] {2,9,14} );
font.put("M",new int[] {9,2,3,5,6,13} );
font.put("N",new int[] {9,2,3,12,13,6} );
font.put("O",new int[] {1,2,9,14,13,6} );
font.put("P",new int[] {1,2,6,7,8,9} );
font.put("Q",new int[] {1,2,6,9,14,13,12} );
font.put("R",new int[] {1,2,6,7,8,9,12} );
font.put("S",new int[] {1,2,7,8,13,14} );
font.put("T",new int[] {1,4,11} );
font.put("U",new int[] {2,9,14,13,6} );
font.put("V",new int[] {2,9,10,5} );
font.put("W",new int[] {2,9,14,13,6,11} );
font.put("X",new int[] {3,10,5,12} );
font.put("Y",new int[] {3,5,11} );
font.put("Z",new int[] {1,5,10,14} );
font.put(" ",new int[] {} );
font.put(".",new int[] {0} );
font.put(",",new int[] {10} );
font.put("!",new int[] {4,11,0} );
font.put("'",new int[] {4} );
font.put("?",new int[] {1,2,6,8,11,0} );
font.put("&",new int[] {1,3,6,8,9,12,14} );
font.put("+",new int[] {4,7,8,11} );
font.put("-",new int[] {7,8} );
}
void drawChar(String c, float x, float y, float w, float h){
int[] segs = (int[])font.get(c);
if(segs == null) return;
for(int i = 0; i < segs.length; i++){
switch(segs[i]){
case 1:
line(x,y,x+w,y); break;
case 2:
line(x,y,x,y+(h/2));break;
case 3:
line(x,y,x+(w/2),y+(h/2));break;
case 4:
line(x+(w/2),y,x+(w/2),y+(h/2));break;
case 5:
line(x+w,y,x+(w/2),y+(h/2)); break;
case 6:
line(x+w,y,x+w,y+(h/2));break;
case 7:
line(x,y+(h/2),x+(w/2),y+(h/2));break;
case 8:
line(x+(w/2),y+(h/2),x+w,y+(h/2));break;
case 9:
line(x,y+(h/2),x,y+h);break;
case 10:
line(x,y+h,x+w/2,y+h/2);break;
case 11:
line(x+w/2,y+h/2,x+w/2,y+h);break;
case 12:
line(x+w/2,y+h/2,x+w,y+h);break;
case 13:
line(x+w,y+h/2,x+w,y+h);break;
case 14:
line(x,y+h,x+w,y+h);break;
case 0:
line(x+w/2-w/6,y+h+h/4,x+w/2+w/6,y+h+h/4);break;
default:
break;
}
}
}