Nov 24, 2008

Extract font outlines

I find this tip from the talk: Doing Physics with Mathematica 6 by Michael Trott

 

GCText[text_,tsize_]:= ImportString[ExportString[Cell[TextData[StyleBox[
text, FontWeight->"Bold",FontFamily->"Helvetica"]], "Text", tsize], "PDF"]][[1]]

outlines =  (First /@ Cases[GCText["ABC", 20], _Polygon, Infinity]);

Graphics3D[{FaceForm[],EdgeForm[Black],Polygon[Map[Append[#, 10]&, outlines, {-2}]]}];

for fun:

image

2 comments:

Anonymous said...

Can you explain what happened inside GCText there?

Ragfield said...

Anonymous,

Mathematica doesn't have a built in function to convert text into glyph outlines. This trick takes advantage of the knowledge that Mathematica's PDF import implementation converts text into polygons. So by exporting text as PDF, then immediately importing that PDF, one can effectively turn text into glyph outlines. From there this example converts the 2D polygons into 3D polygons (by adding 10 as the z component of each point).