meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:design_guide_text [2020/12/03 03:04] JSCAD Editor |
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.// | ||
Line 17: | Line 17: | ||
<code javascript> | <code javascript> | ||
- | let outlines = vectorChar(' | + | const { vectorChar } = require(' |
- | let outlines = vectorChar({ height: 50 }, ' | + | |
+ | const outlines = vectorChar(' | ||
+ | const outlines = vectorChar({ height: 50 }, ' | ||
</ | </ | ||
Line 24: | Line 26: | ||
<code javascript> | <code javascript> | ||
+ | const { path2 } = require(' | ||
+ | |||
const segmentToPath = (segment) => { | const segmentToPath = (segment) => { | ||
- | return | + | return path2.fromPoints({close: |
} | } | ||
- | let paths = outlines.segments.map((segment) => segmentToPath(segment)) | + | const paths = outlines.segments.map((segment) => segmentToPath(segment)) |
</ | </ | ||
Line 35: | Line 39: | ||
=== Text Strings === | === Text Strings === | ||
- | In addition to single characters, complete text strings can be converted to a series of outlines, i.e. small line 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 48: | Line 52: | ||
<code javascript> | <code javascript> | ||
- | let outlines = vectorText(' | + | const { vectorText } = require(' |
- | let outlines = vectorText({ yOffset: -90, height: 10, extrudeOffset: | + | |
- | let outlines = vectorText({ height: 25, align: ' | + | const outlines = vectorText(' |
+ | const outlines = vectorText({ yOffset: -90, height: 10, extrudeOffset: | ||
+ | const outlines = vectorText({ height: 25, align: ' | ||
+ | </ | ||
+ | |||
+ | Again, you will have to convert the output of `vectorText` into a list of paths before it becomes actually useful: | ||
+ | |||
+ | <code javascript> | ||
+ | const { path2 } = require(' | ||
+ | |||
+ | const segmentToPath = (segment) => { | ||
+ | return path2.fromPoints({close: | ||
+ | } | ||
+ | |||
+ | const paths = outlines.map((segment) => segmentToPath(segment)) | ||
</ | </ | ||
=== Using Other Fonts === | === Using Other Fonts === | ||
- | The default font ([[http:// | + | The default font ([[http:// |
- | Other fonts can be used when creating | + | Once the custom ' |
- | - Download one or more font files from the fonts/ | + | - Create a new project |
- | - Include | + | - Copy the custom ' |
- | - Reference | + | - 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. There are libraries that create outlines from TrueType (and other) fonts.//** | + | **//Special Note: These fonts are ' |