Tuesday, 5 February 2013

OpenSCAD Bitmap Font

An (almost) 32 bit font for OpenSCAD.

I have used Tony Buser's bitmap OpenSCAD font to add 3D letters to various objects. I recently wanted to to get higher resolution than 8 bits but did not want the more complicated workflow (of which there are a number of examples 1 2 ) of creating the letters outside of OpenSCAD as a DXF, then importing them and linear extruding to get the desired 3D objects.

The solution was to use "The Dot Factory" which is designed for creating bitmaps for graphics LCDs. It allows you to import a system font (I used Lucida Console at 24pts) and export that as a text file with each character mapped to a number of bytes representing the bitmap. For example the letter "a"

    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00011111, 0b11000000, //    #######    
    0b01111111, 0b11110000, //  ###########  
    0b01100000, 0b01111000, //  ##      #### 
    0b00000000, 0b00111000, //           ### 
    0b00000000, 0b00111000, //           ### 
    0b00000000, 0b00111000, //           ### 
    0b00000000, 0b00111000, //           ### 
    0b00001111, 0b11111000, //     ######### 
    0b00111111, 0b11111000, //   ########### 
    0b01111000, 0b00111000, //  ####     ### 
    0b11110000, 0b00111000, // ####      ### 
    0b11100000, 0b00111000, // ###       ### 
    0b11100000, 0b00111000, // ###       ### 
    0b11100000, 0b00111000, // ###       ### 
    0b11110000, 0b11111000, // ####    ##### 
    0b01111111, 0b10011111, //  ########  #####
    0b00011111, 0b00001111, //    #####    ####
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //               
    0b00000000, 0b00000000, //


 
With some text manipulation (in my case using notepad++, which is excellent) this is converted into:
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,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0,0,0,0,
    1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,
    0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
    0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,
    0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0



The matrix above is the format that Tony Buser's open scad bitmap drawer uses, define the number of bits per row and you are away:

Still a bit chunky but less so than the original 8 bit version:
The full list of characters created are:


ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789

 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~


Depending on the character the bitmaps are 8,16,24 or 32 bits wide and the bitmaps are all 31 bits high.

If you render them all at once they can use quite a bit of processing power, best to leave extensive 3d lettering until the rest of the object is designed.

The OpenSCAD script is available on github.
 
Update: Inkscape has a plug-in to export direct to OpenSCAD so this may make that method easier - one to check next time!

No comments:

Post a Comment