OpenSCAD Variable Width Text -- TrueType(TTF) Font to DXF Converter

by jas, published

OpenSCAD Variable Width Text -- TrueType(TTF) Font to DXF Converter by jas May 31, 2013


Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

8736Views 3007Downloads


Come on people! Let's have some variable-width love in the OpenSCAD font arena! Here is a C program that converts TTF fonts into DXF that is suitable for import and extrusion in OpenSCAD. Bonus: it includes DIMENSION information that can be used by the dxf_dim OpenSCAD function to layout the text based on character metric information that was in the font.


Take a look at the README... there is a C program that can be compiled with pretty much only freetype2 libraries as a dependency. This can be used to generate a DXF file that can be used in OpenSCAD. Take a look at the examples for how to access character metric info. Maybe someone (hint hint) can adapt the widely used Write.SCAD to use (optionally) this method to lay out characters in various geometries.

All Apps

Upgrade this Thing with Thingiverse Apps

No results.

Note that you need at least OpenSCAD 2014.03 for the provided sample code to run. Under OpenSCAD 2013 it fails to compile. Under 2015, the sample code uses deprecated functions. Here's my alternative code that writes a word:

function sumv(v,i,s=0) = (i==s ? v[i] : v[i] + sumv(v,i-1,s));

module letter(wrd,font="font.dxf",h=10,i=0)
import(font, layer=wrd[i]);

module word(wrd,font="font.dxf",h=100,i=0,kerning=1)
widths = [ for (i = [0 : len(wrd)-1]) dxf_dim(file=font, name="advx",layer=wrd[i]) ];
for(i = [i : len(wrd)-1])
if(i > 0)
offset = sumv(widths,i-1,0)*kerning;

scale(0.1) word("Hello",kerning=1);

Nice achievement ! Now we can render any font we want !

a little bug report thought :
In "hello_world.scad" we need a "children()" statement after the "word()" in "word" function. Otherwise the "children()" in the else case does not bind to anything, because there is nothing after the "word()" statement. (BTW: "child" is deprecated)
In clear:
module word(wrd,font="font.dxf",h=100,i=0)
if(i < len(wrd))
letter(wrd,font,h,i) word(wrd,font,h,i+1) children();

I have made a custom implementation of this tool here : http://www.trustfm.net/GeneralTools/Font2OpenSCAD.phphttp://www.trustfm.net/General...
Font2OpenSCAD support "multi language" . Let me know your thoughts


works fine with arial. i used it on a raspberry pi computer.
when i used symbol fonts like "wingdings2.ttf" got:

./ttf2dxf -f WINGDNG2.TTF > wingdings2.dxf
Fatal error in FT_Get_Char_Index: no error (0) at line:407

any solution?

thanks alex

I would guess there is a missing glyph in the font that it expects. Presumably you trying to generate the whole ASCII printable set (that's what the code does by default). Hm... I'll upload an (untested) version that just blindly skips undefined characters. Give that a try and let me know what happens.

BTW: thanks to Chris Radek for TTT to give me a start: http://timeguy.com/cradek/truetypehttp://timeguy.com/cradek/true...