Measuring and wrapping text in OpenSCAD

Measuring and wrapping text in OpenSCAD

thingiverse

OpenSCAD does not offer built-in functionality for measuring text size or word wrapping text. This library fills that gap.\r\n\r\nTo use this library, ensure you have `fontmetricsdata.scad` and `fontmetrics.scad` in your current directory and start your code with\r\n\r\n use <fontmetrics.scad>;\r\n\r\nPublic modules:\r\n* `drawWrappedText(text, font="Liberation Sans", size=10, spacing=1, linespacing=1, indent=0, width=800, halign="left")`: wrap `text` to the specified width; you can have multiple paragraphs separated by `\n`, and you can choose `"left"`, `"right"`, and `"justify"` as the alignment\r\n* `drawText()`: a partial clone (minus the language, script and only good for left-to-right) of the built-in `text()`, but with greater rendering fidelity at small font sizes\r\n\r\nPublic functions:\r\n* `measureText(text, font="Liberation Sans", size=10., spacing=1.)`: measure the width of text; this is, technically, the x-advance of the text, so the text--especially in italics--may stick out the right hand side\r\n* `measureTextBounds(text, font="Liberation Sans", size=10., spacing=1., valign="baseline", halign="left")`: returns `[[leftX,bottomY],[width,height]]` of the rectangle taken up by the actual text; curves near edges may slightly spill out\r\n* `measureWrappedText(text, font="Liberation Sans", size=10, spacing=1, linespacing=1, indent=0, width=800, halign="left")`: same as `measureTextBounds()` except that it measures the text as rendered by `drawWrappedText()` instead of `drawText()/text()`.\r\n* `measureTextAscender(text, font="Liberation Sans", size=10., valign="baseline")`: measures the ascenders of the single-line text (height above baseline)\r\n* `measureTextDescender(text, font="Liberation Sans", size=10., valign="baseline")`: measures the bottom of the single-line text relative to the baseline (typically negative)\r\n* `measureLeftBearing(text, font="Liberation Sans", size=10.)`: measures the distance from the left of the beginning of the shape of the first glyph in `text` (single line)\r\n* `measureRightBearing(text, font="Liberation Sans", size=10.)`: measures the distance from the right-advance of the text to the right-hand-side of the shape of the last glyph in `text` (single line)\r\n* `ascender(font="Liberation Sans", size=10.)`: the ascender size reported by the font\r\n* `descender(font="Liberation Sans", size=10.)`: the descender size reported by the font\r\n\r\nThe library includes metrics and kerning information for the OpenSCAD built-in Liberation fonts plus all the text fonts in the [Microsoft Core Fonts](https://en.wikipedia.org/wiki/Core_fonts_for_the_Web) package. It won't work with other fonts, unless you use [my Python scripts](https://github.com/arpruss/zttf) to generate more font information. \r\n\r\n**Updates:**\r\n* 08/22/2019: Bug fixes\r\n* 07/18/2018: Webdings support\r\n* 07/17/2018: tweak side-bearing and ascender and descender measurement; change return format for bounds; add text wrapping

Download Model from thingiverse

With this file you will be able to print Measuring and wrapping text in OpenSCAD with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Measuring and wrapping text in OpenSCAD.