meta data for this page
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
en:design_guide_text [2020/11/28 02:55] JSCAD Editor created |
en:design_guide_text [2022/04/14 08:32] (current) rozek included "require" statements, corrected mistakes |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ==== Text ==== | ==== Text ==== | ||
| - | Text can be used in designs to create the outline of charaters, which can then be used to create either 2D or 3D shapes. | + | Text can be used in designs to create the outline of characters, which can then be used to create either 2D or 3D shapes. |
| //NOTE: Only the ASCII characters can be used today.// | //NOTE: Only the ASCII characters can be used today.// | ||
| === Single Characters === | === Single Characters === | ||
| - | A single character can be converted into an outline, i.e. segments. The character height as well as the character position can be requested by specifying options. The height is the height of UPPERCASE characters. | + | |
| + | A single character can be converted into an outline, i.e. an array of line segments. The character | ||
| Defaults: | Defaults: | ||
| Line 16: | Line 17: | ||
| <code javascript> | <code javascript> | ||
| - | let char1 = vectorChar(' | + | const { vectorChar } = require(' |
| - | let char2 = vectorChar({ height: 50 }, ' | + | |
| + | const outlines | ||
| + | const outlines | ||
| </ | </ | ||
| - | //Note: The old function vector_char(x, | + | The above examples |
| - | + | ||
| - | The above example | + | |
| <code javascript> | <code javascript> | ||
| - | let shape1 | + | const { path2 } = require(' |
| - | let shape2 = csgFromSegments(char2.segments); | + | |
| - | function csgFromSegments | + | const segmentToPath = (segment) => { |
| - | | + | |
| - | segments.forEach(segment => output.push( | + | |
| - | rectangular_extrude(segment, | + | |
| - | )); | + | |
| - | return union(output); | + | |
| } | } | ||
| + | |||
| + | const paths = outlines.segments.map((segment) => segmentToPath(segment)) | ||
| </ | </ | ||
| + | |||
| + | And of course, the paths can be used to create additional shapes, including 3D shapes of the characters. | ||
| === Text Strings === | === Text Strings === | ||
| - | In addition to single characters, complete text strings can be converted to a series of outlines, i.e. segments. Text can be split into multiple lines by including ' | + | In addition to single characters, complete text strings can be converted to a series of outlines, i.e. line segments. Text can be split into multiple lines by including ' |
| Defaults: | Defaults: | ||
| Line 51: | Line 51: | ||
| * font : ' | * font : ' | ||
| - | //Note: The old function vector_text(x,y,string) is also available but will be deprecated in the V2 API.// | + | <code javascript> |
| + | const { vectorText } = require(' | ||
| + | |||
| + | const outlines = vectorText(' | ||
| + | const outlines = vectorText({ yOffset: -90, height: 10, extrudeOffset: | ||
| + | const outlines = vectorText({ height: 25, align: ' | ||
| + | </ | ||
| + | |||
| + | Again, you will have to convert | ||
| <code javascript> | <code javascript> | ||
| - | let text1 = vectorText('OpenJSCAD'); | + | const { path2 } = require('@jscad/ |
| - | let text2 = vectorText({ yOffset: -90, height: 10, extrudeOffset: | + | |
| - | let text3 = vectorText({ height: 25, align: ' | + | const segmentToPath |
| + | return path2.fromPoints({close: false}, segment) | ||
| + | } | ||
| + | |||
| + | const paths = outlines.map((segment) => segmentToPath(segment)) | ||
| </ | </ | ||
| === Using Other Fonts === | === Using Other Fonts === | ||
| - | Other fonts can be used when creating the text outlines. Here are the steps. | + | The default font ([[http:// |
| - | - Download one or more font files from the fonts/ | + | Once the custom ' |
| - | - Include | + | |
| - | - Reference | + | - Create a new project |
| + | - Copy the custom ' | ||
| + | - Require | ||
| - Specify the ' | - Specify the ' | ||
| - | //Note: Font objects append | + | <code javascript> |
| + | const { path2 } = require(' | ||
| + | const { vectorText } = require(' | ||
| - | Default: | + | const myfont = require(' |
| - | * font: [[http://paulbourke.net/dataformats/hershey/|hershey simplex]] | + | |
| - | <code javascript> | + | const segmentToPath = (segment) => { |
| - | include(' | + | |
| - | + | ||
| - | function main (params) { | + | |
| - | | + | |
| - | let text = vectorText({font: myfont, height: 5},' | + | |
| - | return csgFromSegments(text); | + | |
| } | } | ||
| - | + | ||
| - | function csgFromSegments | + | const main = () => { |
| - | | + | |
| - | segments.forEach(segment => output.push( | + | |
| - | rectangular_extrude(segment, | + | return |
| - | )); | + | |
| - | return | + | |
| } | } | ||
| + | |||
| + | module.exports = {main} | ||
| </ | </ | ||
| - | **//Special Note: These fonts are NOT TrueType fonts. | + | **//Special Note: These fonts are ' |