March 27, 2021
Description
The standard OpenSCAD fonts work well for a simple extrusion 3D profile. But what if you want a different 3D profile, e.g., you want text that looks like it's been machined with a V-shaped bit, or text that is rounded in 3D?
This library includes the ASCII portions of the Hershey vector fonts, and draws text using whatever convex shape you specify. For instance, you can do rounded text via:
use <hershey.scad>;
drawHersheyFont("Hello, OpenSCAD!", font="Script") sphere(r=2,$fn=16);
A call to drawHersheyFont() requires a child object that specifies what the drawing is done with. The drawing is done by putting the child object at the two endpoint of a lines and doing a hull() operation.
The following optional arguments are available:
halign="left"|"right"|"center": horizontal alignmentvalign="top"|"baseline"|"center"|"bottom": vertical alignmentsize=x: specify height of capital TextraSpacing=x: add this extra spacing between letters (can be negative)forceMinimumDistance=d: make sure that the distance (not necessarily horizontal) between successive glyphs is as close to d as reasonably possible; use this if you want to draw fat letters that overlap by the same amount, like hereminimumDistancePrecision=p: set the precision for the forceMinimumDistance option
There is also a function to measure text width: widthHersheyText(text, font=name), with optional size=x and extraSpacing=x parameters.
Unfortunately CGAL rendering is going to be very slow. The "Hello, OpenSCAD!" CGAL render took about three minutes.
Note the licensing on the Hershey library in the source code, which isn't fully compatible with Creative Commons -- but the restrictions are very, very slight.
Updates:
August 16, 2019: Optimize file size of hershey.scad for faster loading.
August 10, 2019: Added Latin1 accented characters. Fixed baseline alignment. Renamed fonts to be more intuitive (old names are still supported). Removed duplicate fonts.
License:
CC BY - Attribution