Skip to content

Commit

Permalink
Add currentdesignspace examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
LettError committed Sep 25, 2023
1 parent bf8a03f commit eb1c935
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions DesignspaceEditor2.roboFontExt/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h2 id="toc">Contents</h2>
<li><a href="#toc_10">Notes Tab</a></li>
<li><a href="#toc_11">Notifications</a></li>
<li><a href="#toc_12">Receiving and responding to notifications</a></li>
<li><a href="#toc_13">Scripting with the current designspace</a></li>
</ul>

<h2 id="toc_1">Designspace Editor Usage <a href="#toc"></a></h2>
Expand Down Expand Up @@ -934,5 +935,39 @@ <h3 id="toc_12">Receiving and responding to notifications<a href="#toc">↑</a><
</ul>


<h2 id="toc_13">Scripting with the current designspace<a href="#toc"></a></h2>

With a document open in DesignspaceEditor you can call <code>CurrentDesignspace()</code>, similar to <code>CurrentFont()</code> and <code>CurrentGlyph()</code>. This returns the designspace wrapped in a <code>UFOOperator</code> object that can calculate single glyphs, kerning and font info.

<h3>Calculating a glyph</h3>
The example below calculates a single glyph at the default location. It returns a mathGlyph.

<code>
<pre>d = CurrentDesignspace()
d.loadFonts()
loc = d.newDefaultLocation()
g = d.makeOneGlyph("A", location=loc)
</pre>
</code>


<h3>Calculating kerning and info</h3>
The example below calculates a single kerning pair and an info object. <code>makeOneKerning</code> accepts a list of pairs to calculate. If no pairs are given, all pairs will be calculated.

<code>
<pre>d = CurrentDesignspace()
d.loadFonts()
loc = d.newDefaultLocation()

pairs = [('public.kern1.i', 'public.kern2.b')]
kern = d.makeOneKerning(loc, pairs)
print(kern.items())

info = d.makeOneInfo(loc)
print(info)
</pre>
</code>


</body>
</html>

0 comments on commit eb1c935

Please sign in to comment.