281 lines
14 KiB
HTML
281 lines
14 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>How to: Glyph Math</title>
|
||
|
<link href="../default.css" type="text/css" rel="stylesheet" />
|
||
|
</head><body>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
_uacct = "UA-2044310-2";
|
||
|
urchinTracker();
|
||
|
</script>
|
||
|
|
||
|
<div id="modellogo">
|
||
|
<img src="../img/drawmodel_header.jpg" width="595" height="112" />
|
||
|
</div>
|
||
|
<div class="leftcontent">
|
||
|
<h1 class="crb-seealso">
|
||
|
RoboFab
|
||
|
</h1>
|
||
|
<p class="menu">
|
||
|
<a href="../index.html">
|
||
|
Home
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../download/index.html">
|
||
|
Download v1.1.1
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../intro.html">
|
||
|
Intro
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../install.html">
|
||
|
Install Notes
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../history.html">
|
||
|
History
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../executive.html">
|
||
|
Summary
|
||
|
</a>
|
||
|
</p>
|
||
|
|
||
|
<p class="menu">
|
||
|
<a href="index.html">
|
||
|
How to's
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../talks/index.html">
|
||
|
Step by step
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../tools/dialogs.html">
|
||
|
Fab Dialogs
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../objects/index.html">
|
||
|
Object reference
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../objects/model.html">
|
||
|
Object map
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../tools/index.html">
|
||
|
Tools
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../ufo/index.html">
|
||
|
UFO Overview
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../ufo/specification.html">
|
||
|
UFO Spec
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../limitations.html">
|
||
|
Fab Limitations
|
||
|
</a>
|
||
|
|
||
|
<a href="../links/index.html">
|
||
|
Links
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../credits.html">
|
||
|
Credits
|
||
|
</a>
|
||
|
</p>
|
||
|
|
||
|
<h1 class="crb-seealso">
|
||
|
Support RoboFab
|
||
|
</h1>
|
||
|
|
||
|
|
||
|
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
||
|
<input type="hidden" name="cmd" value="_s-xclick">
|
||
|
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
|
||
|
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
|
||
|
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHRwYJKoZIhvcNAQcEoIIHODCCBzQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYCwSKfv3n+m7gMAQttRdiUdaGxSHt2oKSNvYzSFsBPjNsxmwva6gPCPUFV5sfJY1QJQuzQk8iXLqxb/mKmdoWc8Z2Eq7+rUtgo0149vBg35woLGv8zoMkgbghCcHJjdclAl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
|
|
||
|
|
||
|
|
||
|
<h2 class="crb-seealso">
|
||
|
Up
|
||
|
</h2>
|
||
|
|
||
|
<p class="menu">
|
||
|
<p class="bonbon_uplink"><a href="index.html">Back to How To</a></p>
|
||
|
</p>
|
||
|
|
||
|
<h2 class="crb-seealso">
|
||
|
See also
|
||
|
</h2>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<p class="menu">
|
||
|
<a href="../glossary/glyphmath.html">Glossary: GlyphMath</a><br /><a href="../objects/component.html">RComponent</a><br /><a href="../objects/contour.html">RContour</a><br /><a href="../objects/font.html">RFont</a><br /><a href="../objects/glyph.html">RGlyph</a><br /><a href="../objects/lib.html">RLib</a><br /><a href="../objects/pen.html">Pen objects</a><br /><a href="../talks/robofab_session2.html">Glyph object and Pen object</a><br /><a href="../talks/robofab_session3.html">Kerning object and glyph building</a><br /><a href="../talks/robofab_session5.html">Interpolation</a><br /><a href="interpolate.html">How to interpolate</a><br /><a href="usetransformations.html">Using transformations</a><br />
|
||
|
</p>
|
||
|
</div>
|
||
|
|
||
|
<div class="footer">
|
||
|
<a href="../feedback.html">
|
||
|
Feedback
|
||
|
</a>
|
||
|
<br />
|
||
|
<a href="../map.html">
|
||
|
Sitemap
|
||
|
</a>
|
||
|
<br />
|
||
|
Please also refer to the
|
||
|
<a href="../download/license.html">
|
||
|
Legal
|
||
|
</a>
|
||
|
<br />
|
||
|
Copyright 2003-2006 RoboFab
|
||
|
<br />
|
||
|
version 1.1.1
|
||
|
</div>
|
||
|
|
||
|
<div class="google">
|
||
|
|
||
|
|
||
|
<h2>RoboFab Mailinglist</h2>
|
||
|
<p>
|
||
|
Join the RoboFab users community at Google groups.
|
||
|
</p>
|
||
|
|
||
|
|
||
|
<img src="http://groups.google.com/groups/img/3nb/groups_bar.gif" alt="Google Groups" height="26" width="132" />
|
||
|
|
||
|
<p>
|
||
|
<form action="http://groups.google.com/group/robofab/boxsubscribe">
|
||
|
Email: <input type="text" name="../email" />
|
||
|
<input type="submit" name="../sub" value="Subscribe" />
|
||
|
</form>
|
||
|
</p>
|
||
|
<p>
|
||
|
<a href="http://groups.google.com/group/robofab">Visit this group</a>
|
||
|
</p>
|
||
|
|
||
|
|
||
|
<h2>RoboFab Sponsors</h2>
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
|
||
|
|
||
|
google_ad_client = "pub-3703953449723704";
|
||
|
google_ad_width = 120;
|
||
|
google_ad_height = 600;
|
||
|
google_ad_format = "120x600_as";
|
||
|
google_ad_type = "text_image";
|
||
|
google_ad_channel ="";
|
||
|
google_color_border = "336699";
|
||
|
google_color_bg = "FFFFFF";
|
||
|
google_color_link = "0000FF";
|
||
|
google_color_url = "008000";
|
||
|
google_color_text = "000000";
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</script>
|
||
|
|
||
|
|
||
|
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div class="content">
|
||
|
<h1>Glyph Math</h1>
|
||
|
<p>
|
||
|
RGlyph objects have methods that allow the objects to behave a bit like variables in simple math. These methods do not do additions or substractions of the surface area of the glyphs, like layering two glyphs on top of each other and than doing "remove overlap". Instead, they return new glyph objects in which each coordinate in each contour is the product of the two glyphs.
|
||
|
</p>
|
||
|
<h2>Objects</h2>
|
||
|
<p>
|
||
|
All glyph math operations in have new, orphaned, objects as result. For instance a substraction of two FontLab RoboFab glyphs will result in a new glyph object, but it won't be part of the font. If you want the result to be part of the font you have to add it explicitly, see the example at the bottom of this page. There are several reasons for this:
|
||
|
</p>
|
||
|
<ul>
|
||
|
<li>
|
||
|
the result might not even come from glyphs in the same font, i.e. you can substract a glyph in one font from a glyph in another font. Where should the result live? you decide.
|
||
|
</li>
|
||
|
<li>
|
||
|
You might not want the result to be part of your font when you're using it for further calculations. So: results from glyphmath operations are orphan glyphs that do not belong to any font.
|
||
|
</li>
|
||
|
<li>
|
||
|
the results need to use floating point (19.234943) numbers for precision, FontLab only stores integer numbers (19)
|
||
|
</li>
|
||
|
</ul>
|
||
|
<p>
|
||
|
If you want to add a glyph (of any flavor, FontLab or UFO) to a font use the appendGlyph method:
|
||
|
</p>
|
||
|
|
||
|
<div class="pythonsource"><pre><span class="py_key">someNewGlyph</span> = <span class="py_key">aFont</span>.<span class="py_key">newGlyph</span>(<span class="py_str">"someNewGlyph"</span>)<br><span class="py_key">someNewGlyph</span>.<span class="py_key">appendGlyph</span>(<span class="py_key">restultFromGlyphMath</span>)<br> <br># note you have to set the width, appendGlyph does not automatically<br># take the value.<br><span class="py_key">someNewGlyph</span>.<span class="py_key">width</span> = <span class="py_key">restultFromGlyphMath</span>.<span class="py_key">width</span></pre></div>
|
||
|
|
||
|
<h2>Substraction</h2>
|
||
|
<p>
|
||
|
Substraction returns a new glyph object with contours which represent the <strong>difference</strong> between the two previous glyphs. As a glyph itself, it's not much to look at. If you draw the result of a substraction it will probably look like a crumpled outline.
|
||
|
</p>
|
||
|
<h3>Example Substraction</h3>
|
||
|
|
||
|
<div class="pythonsource"><pre><span class="py_key">f</span> = <span class="py_key">CurrentFont</span>()<br><span class="py_key">g</span> = <span class="py_key">f</span>[<span class="py_str">"a"</span>]<br><span class="py_key">h</span> = <span class="py_key">f</span>[<span class="py_str">"b"</span>]<br># suppose g and h have compatible point structures<br><span class="py_key">myRelativeGlyph</span> = <span class="py_key">g</span> - <span class="py_key">h</span></pre></div>
|
||
|
|
||
|
<h2>Addition</h2>
|
||
|
<p>
|
||
|
Addition returns a new glyph object with the contours which is the product of the two previous glyphs. If you just add two "normal" glyphs from a font (or multiple fonts for that matter) it will look odd. But you can also easily add a relative glyph (a result of substracting one glyph from another), which effectively means you're applying the difference between two glyphs to a third. And that can be a very useful action.
|
||
|
</p>
|
||
|
<h3>Example Addition</h3>
|
||
|
|
||
|
<div class="pythonsource"><pre># continue with myRelativeGlyph from the previous example<br><span class="py_key">newglyph</span> = <span class="py_key">f</span>[<span class="py_str">"x"</span>] + <span class="py_key">myRelativeGlyph</span></pre></div>
|
||
|
|
||
|
<h2>Multiplication</h2>
|
||
|
<p>
|
||
|
When a normal glyph is multiplied it looks as if the glyph has been scaled. For instance multiplying a glyph with 0.5 scales the shapes 50%.
|
||
|
</p>
|
||
|
<h3>Example Multiplication</h3>
|
||
|
|
||
|
<div class="pythonsource"><pre># continue with myRelativeGlyph from the previous example<br><span class="py_key">newglyph</span> = <span class="py_key">f</span>[<span class="py_str">"x"</span>] + <span class="py_num">0.25</span> * <span class="py_key">myRelativeGlyph</span></pre></div>
|
||
|
|
||
|
<h2>Division</h2>
|
||
|
<p>
|
||
|
Divisions works just like multiplications, you just need to make sure not to divide by zero.
|
||
|
</p>
|
||
|
<h3>Example Division</h3>
|
||
|
|
||
|
<div class="pythonsource"><pre># continue with myRelativeGlyph from the previous example<br><span class="py_key">newglyph</span> = <span class="py_key">f</span>[<span class="py_str">"x"</span>] + <span class="py_key">myRelativeGlyph</span> / <span class="py_num">4</span></pre></div>
|
||
|
|
||
|
<h2>Combinations</h2>
|
||
|
<p>
|
||
|
These examples are simple enough, but when you combine them the operations can become really powerful. You could recreate font interpolation using GlyphMath, or construct new networks of interpolations, additions, shifts, deltas that were impossible to build.
|
||
|
</p>
|
||
|
<h3>All together now</h3>
|
||
|
<p>
|
||
|
This is from the demo_GlyphMath.py which should be in the Scripts/RoboFabIntro folder.
|
||
|
</p>
|
||
|
|
||
|
<div class="pythonsource"><pre># robofab manual<br># Glyphmath howto<br># Fun examples<br> <br><br>#FLM: Fun with GlyphMath<br> <br># this example is meant to run with the RoboFab Demo Font<br># as the Current Font. So, if you're doing this in FontLab<br># import the Demo Font UFO first.<br> <br><span class="py_res">from</span> <span class="py_key">robofab</span>.<span class="py_key">world</span> <span class="py_res">import</span> <span class="py_key">CurrentFont</span><br><span class="py_res">from</span> <span class="py_key">random</span> <span class="py_res">import</span> <span class="py_key">random</span><br> <br><span class="py_key">f</span> = <span class="py_key">CurrentFont</span>()<br><span class="py_key">condensedLight</span> = <span class="py_key">f</span>[<span class="py_str">"a#condensed_light"</span>]<br><span class="py_key">wideLight</span> = <span class="py_key">f</span>[<span class="py_str">"a#wide_light"</span>]<br><span class="py_key">wideBold</span> = <span class="py_key">f</span>[<span class="py_str">"a#wide_bold"</span>]<br> <br><span class="py_key">diff</span> = <span class="py_key">wideLight</span> - <span class="py_key">condensedLight</span><br> <br><span class="py_key">destination</span> = <span class="py_key">f</span>.<span class="py_key">newGlyph</span>(<span class="py_str">"a#deltaexperiment"</span>)<br><span class="py_key">destination</span>.<span class="py_key">clear</span>()<br><span class="py_key">x</span> = <span class="py_key">wideBold</span> + (<span class="py_key">condensedLight</span>-<span class="py_key">wideLight</span>)*<span class="py_key">random</span>()<br> <br><span class="py_key">destination</span>.<span class="py_key">appendGlyph</span>( <span class="py_key">x</span>)<br><span class="py_key">destination</span>.<span class="py_key">width</span> = <span class="py_key">x</span>.<span class="py_key">width</span><br> <br><span class="py_key">f</span>.<span class="py_key">update</span>()<br></pre></div><div class="pythonsourcetitle"><a href="examples/gmathFun.py" target="new">download examples/gmathFun.py</a></div>
|
||
|
|
||
|
<h2>Implementation limits</h2>
|
||
|
<p>
|
||
|
In objectsFL (for use in FontLab), only RGlyph has glyphmath operators implemented. The result of a glyphmath operation in FontLab is <strong>always</strong> an object from objectsRF. In ObjectsRF most objects have *, + and - implemented. But considering the operators are mainly used for Glyph stuff, the RGlyph object is a bit more kitted out with division as well.
|
||
|
</p>
|
||
|
</div>
|
||
|
</body></html>
|