Calculating the density of characters was rather easy in Borland's IDE. Let im be an image, then:
im->Canvas->Font=font_you_use_for_conversion;
int width=im->Canvas->TextWidth('x'),height=im->Canvas->TextHeight('x');
Now we have the size of a character. The font is monospaced so I can use 'x' or any other character. Now for ch being each character in turn, I clear the image, then print the character on it:
im->Canvas->TextOutA(10,10,ch);
int counter=0;
Then in loop where i changes from, say, 0 to width+10 and j from 0 to height+10:
counter+=im->Canvas->Pixels[i][j]&0x0000FF;
Finally, the density of ink for this character is:
1-(double)counter/255/width/height
Note that the area that you check inside the (i;j) loop must be greater than the character width*height rectangle because a lot of characters exceed this size. The size is used only to determine the horizontal and vertical distance between characters.
Note also that just counting black pixels in the loop is not a good idea, because some fonts, especially small sized (like 2 or 3) include also some gray pixels which also have to be counted in.
Finally I cut the input image into width*height rectangles and for each of them I calculate the density of ink in a similar way as I did it for characters (only now I have to take into account all colors, and also the color weights) and for each rectangle I use the character that fits best.
This is not the actual code of the program, but I think it is more or less correct and shows the main idea