OpenSCAD User Manual/WIP

Work in ProgressEdit

OverviewEdit

This section contains documentation about ongoing work which is available as experimental features in snapshot versions of OpenSCAD or not yet integrated at all and pending in a branch or pull-request at the OpenSCAD github repository.

Information listed here is mainly intended to help people using and testing the experimental features to provide feedback. It's likely that there are changes to the API and behavior of the features before those are officially released.

NOTE: If the feature mentioned here is already included in the snapshot builds, it's normally also required to enable the feature in the Preferences dialog!

Text Metrics / Font MetricsEdit

textmetricsEdit

textmetrics() returns information about the size and positioning that would be applied to text if laid out as specified by its arguments.

Parameters

The parameters to textmetrics() are exactly the same as the parameters to text().

Return value

The return value from textmetrics() is an object with these properties:

position an [x,y] pair giving the lower left corner of the smallest box that would completely surround the text.

size an [x,y] pair giving the size of that box.

ascent the vertical distance (normally positive) from the baseline of the text to the highest point in the text.

descent the vertical distance (normally zero or negative) from the baseline of the text to the lowest point in the text.

offset an [x,y] pair giving the distance from the origin to the starting point of the baseline of the text. This value is normally [0,0] but can be non-zero when using non-default alignments.

advance an [x,y] pair giving the distance from the starting point for this text to the starting point for a subsequent piece of text. Informally, it says how far the pen should be moved before starting the next piece of text. This value is directly helpful only with default alignments - horizontal text aligned left/baseline and vertical text aligned center/top.

Note: as with any array, you can use an object-like ".x" or ".y" to refer to the two entries in [x,y] pairs. Thus you can refer to either obj.size[0] or obj.size.x to get the X dimension of the text.

 
Information returned by textmetrics() function.

Sample output (reformatted for readability):

 ECHO: {
   position = [2.2784, -5.7728];
   size = [87.0362, 24.8832];
   ascent = 19.1104;
   descent = -5.7728;
   offset = [0, 0];
   advance = [89.5186, 0];
 }

fontmetricsEdit

fontmetrics() returns information about the specified font and size.

The arguments to fontmetrics() are the size and font name.

Parameters

size the font size font the font name

Return value

The return value from fontmetrics() is an object with these properties:

nominal an object with ascent and descent properties describing the "usual" ascent and descent of the font. For most fonts, this will be the ascent of upper-case letters and the descent of lower-case letters with descenders.

max an object with ascent and descent properties describing the maximum ascent and descent of the font.

interline gives, as a positive number, the designed inter-line spacing for the font.

font an object with members family and style that gives the name and style of the selected font. These may not be the same as the name supplied, if the specified font is not available, or if a generic name like "sans" or "serif" is specified, or if only a style is specified.

Persistent CacheEdit

IntroductionEdit

The cache data of rendered geometries in OpenSCAD is limited to the life-span of the application. This feature provides a solution for the persistent storage of rendered geometries. All the rendered geometries are serialized using boost serialization library and pushed into local filesystem cache or into the Redis database according user preferences.

How to use redis for cache?Edit

  • Download and install Redis database
  • Download Hiredis release version 0.14.1 or above from, build and install it.
  • The source code of this feature is not merged yet. It is available in this PR https://github.com/openscad/openscad/pull/3316. Clone and build this PR.
  • Start the Redis-server and make a note of IP address, port number, and password if any from it's config file.
  • GUI MODE: Open the preferences dialog and move to the advance tab. enable the checkbox persistent cache using Redis. fill in the config details and close the preferences dialog.
 
Persistent cache for openscad
  • CLI MODE: a new option cache is added to OpenSCAD. The usage of this option in the case of Redis is shown below.
          example: ""--cache=redis,127.0.0.1,6379,foobared""
  • That's it, now OpenSCAD is ready to use Redis for caching.

How to use local cache?Edit

  • GUI MODE: Open the preferences dialog and move to the advance tab. enable the Local cache checkbox.
  • CLI MODE: This is another variant in cache option. The usage of this option is shown below.
          example: ""--cache=file""
  • That's it, now OpenSCAD is ready to use local filesystem for caching.