Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions docs/_snippets/fonts-and-text.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@
Pass a font object, your text, and a font size. Each character of your text string will become a child model containing the paths for that character.
</p>

<h4>Compatible Font Libraries</h4>

<p>
There are 2 font libraries compatible with Maker.js:
</p>

<ul>
<li>
<b><a href="http://opentype.js.org/">Opentype.js</a></b> by Frederik De Bleser - reads TrueType and OpenType fonts (.ttf, .otf).
Visit the <a href="https://github.com/nodebox/opentype.js">Opentype.js GitHub</a> for API details.
</li>
<li>
<b><a href="https://github.com/foliojs/fontkit">fontkit</a></b> by devongovett - an advanced font engine supporting TrueType, OpenType, WOFF/WOFF2, and font collections (.ttc, .dfont).
fontkit provides additional features including variable fonts, color glyphs (emoji), and advanced OpenType layout features (GSUB/GPOS).
When using fontkit with color fonts, glyphs are automatically organized into layers by color.
</li>
</ul>

<p>
Maker.js uses <a href="http://opentype.js.org/">Opentype.js</a> by Frederik De Bleser to read TrueType and OpenType fonts.
Please visit the <a href="https://github.com/nodebox/opentype.js">Opentype.js GitHub</a> website for details on its API.
The Text model automatically detects which library you're using and handles both transparently.
You will need to know how to load font files before you can use them in Maker.js.
</p>

Expand Down Expand Up @@ -76,7 +93,11 @@ <h4>Loading fonts in the browser</h4>
<h4>Loading fonts in Node.js</h4>

<p>
Use opentype.loadSync(url) to load a font from a file and return a Font object. Throws an error if the font could not be parsed. This only works in Node.js.
<b>With Opentype.js:</b>
</p>

<p>
Use <code>opentype.loadSync(url)</code> to load a font from a file and return a Font object. Throws an error if the font could not be parsed. This only works in Node.js.
</p>

{% highlight javascript %}
Expand All @@ -90,6 +111,25 @@ <h4>Loading fonts in Node.js</h4>
console.log(makerjs.exporter.toSVG(textModel));
{% endhighlight %}

<p>
<b>With fontkit:</b>
</p>

<p>
Use <code>fontkit.openSync(filename)</code> to load a font from a file. fontkit must be installed separately: <code>npm install fontkit</code>
</p>

{% highlight javascript %}
var makerjs = require('makerjs');
var fontkit = require('fontkit');

var font = fontkit.openSync('./fonts/stardosstencil/StardosStencil-Regular.ttf');

var textModel = new makerjs.models.Text(font, 'Hello', 100);

console.log(makerjs.exporter.toSVG(textModel));
{% endhighlight %}

<p>
Finally, a phenomenon to be aware of is that fonts aren't always perfect. You may encounter cases where paths within a character are self-intersecting or otherwise not forming closed geometries.
This is not common, but it is something to be aware of, especially during combine operations.
Expand Down
17 changes: 17 additions & 0 deletions docs/fonts/twemoji/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Twemoji Mozilla (TwemojiMozilla.ttf)
=====================================

This color emoji font is based on the Twemoji project.

Source: https://github.com/mozilla/twemoji-colr

Twemoji Graphics License (CC-BY 4.0)
------------------------------------
Copyright 2019 Twitter, Inc and other contributors
Graphics designed by Twitter, Inc are licensed under CC-BY 4.0:
https://creativecommons.org/licenses/by/4.0/

Font License (Apache License 2.0)
---------------------------------
The font software is licensed under the Apache License, Version 2.0.
http://www.apache.org/licenses/LICENSE-2.0
Binary file added docs/fonts/twemoji/TwemojiMozilla.ttf
Binary file not shown.
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"browserify": "^17.0.0",
"fontkit": "^2.0.4",
"licensify": "^3.1.3",
"mocha": "^10.0.0",
"opentype.js": "^1.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/maker.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"dependencies": {
"@danmarshall/jscad-typings": "^1.0.0",
"@types/bezier-js": "^0.0.6",
"@types/fontkit": "^2.0.8",
"@types/node": "^7.0.5",
"@types/opentype.js": "^0.7.0",
"@types/pdfkit": "^0.7.34",
Expand Down
Loading