220 lines
6.7 KiB
HTML
220 lines
6.7 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 interpolate</title>
|
|
|
|
<link href="../default.css" type="text/css" rel="stylesheet" />
|
|
|
|
</head>
|
|
<body>
|
|
|
|
|
|
|
|
<div id="modellogo">
|
|
<img src="../img/drawmodel_header.jpg" width="595" height="112" />
|
|
</div>
|
|
<div class="leftcontent">
|
|
<h2 class="crb-seealso">
|
|
RoboFab
|
|
</h2>
|
|
<p class="menu">
|
|
<a href="../index.html">
|
|
Home
|
|
</a>
|
|
<br />
|
|
<a href="../download/license.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="../objects/index.html">
|
|
Fab Objects
|
|
</a>
|
|
<br />
|
|
<a href="../objects/model.html">
|
|
Fab Map
|
|
</a>
|
|
<br />
|
|
<a href="../tools/index.html">
|
|
Fab Tools
|
|
</a>
|
|
<br />
|
|
<a href="../ufo/index.html">
|
|
UFO Overview
|
|
</a>
|
|
<br />
|
|
<a href="../limitations.html">
|
|
Fab Limitations
|
|
</a>
|
|
</p>
|
|
<p class="menu">
|
|
<a href="../links/index.html">
|
|
Links
|
|
</a>
|
|
<br />
|
|
<a href="../glossary/index.html">
|
|
Glossary
|
|
</a>
|
|
<br />
|
|
<a href="../credits.html">
|
|
Credits
|
|
</a>
|
|
</p>
|
|
<br />
|
|
<br />
|
|
<p class="crb-uplink"><a href="index.html">Back to How To</a></p>
|
|
|
|
<br />
|
|
<br />
|
|
<p class="menu">
|
|
|
|
</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-2005 RoboFab
|
|
<br />
|
|
version 1.1.1
|
|
</div>
|
|
|
|
|
|
|
|
<div class="content">
|
|
<h1>How to interpolate</h1>
|
|
<p>
|
|
RoboFab's interpolation is independent of the interpolation tools provided in FontLab. First of all that means that you can interpolate UFO fonts without the help of FontLab. It also means that the interpolation engine works different than the one in FontLab.
|
|
</p>
|
|
<h2>Strict</h2>
|
|
<p>
|
|
RoboFab interpolation is very strict. It won't interpolate unless the point structures of both extremes match. It won't mess with the masters, force points or anything. The user has to get it right.
|
|
</p>
|
|
<h3>aGlyph.isCompatible(otherGlyph, report=True)</h3>
|
|
<p>
|
|
Glyph has a method isCompatible() which reports whether or not the point structures are capable of interpolating. With this method you can run through your proposed interpolation first and see if all glyphs work, and perhaps send feedback to the user.
|
|
</p>
|
|
<pre>
|
|
from robofab.world import CurrentFont
|
|
f = CurrentFont()
|
|
a = f["a"]
|
|
print a.isCompatible(f["b"], False)
|
|
>>> False
|
|
</pre>
|
|
<p>
|
|
isCompatible has a flag <strong>report</strong> which if set to True will return a tuple with a report on the incompatibilities.
|
|
</p>
|
|
<pre>
|
|
from robofab.world import CurrentFont
|
|
f = CurrentFont()
|
|
a = f["a"]
|
|
print a.isCompatible(f["b"], True)
|
|
>>> (False, ["Fatal error: contour 0 in glyph a
|
|
and glyph b don't have the
|
|
same number of segments."])
|
|
</pre>
|
|
<h3>aFont.interpolate(factor, minFont, maxFont, suppressError=True, analyzeOnly=False)</h3>
|
|
<p>
|
|
Interpolate by factor between minFont and maxFont. In FontLab the result of the interpolation will be rounded to whole integers. In NoneLab (outside FontLab, operating on a UFO), the result of the interpolation is a font with glyphs with floating point coordinates so if you want to use the result of one interpolation as a master in the next you won't loose precision to rounding errors. It might mean that for some uses of UFO you need to round the glyphs afterwards. aFont.interpolate also interpolates the positions of components, anchors, ascender, descender, and glyph widths for the whole font.
|
|
</p>
|
|
<br />
|
|
|
|
<ul>
|
|
<li>
|
|
<strong>factor</strong> either a number or a tuple of numbers. Usually factor is a float number between 0 and 1. 0 produces minGlyph, 1 produces maxGlyph. Values > extrapolates beyong maxGlyph. Values < extrapolate beyond minGlyph. If you pass (x, y) to factor it will interpolate horizontal values differently from vertical values. For instance (0, 1) as factor produces a font (or a glyph) which horizontally looks like the minimum, but vertically it looks like the maximum.
|
|
</li>
|
|
<li>
|
|
<strong>minFont</strong> RFont object, the font for the minimum master.
|
|
</li>
|
|
<li>
|
|
<strong>maxFont</strong> RFont object, the font for the maximum master.
|
|
</li>
|
|
<li>
|
|
<strong>suppressError</strong> (optional) will supress all tracebacks it finds on the way. That means that interpolation problems in individual glyphs won't stop the rest of the font from getting done. Default set to True.
|
|
</li><li>
|
|
<strong>analyzeOnly</strong> (optional) will do a dry run of the interpolation and do a full analysis of the compatibility and problems. It won't produce any outlines in the font. Default set to False.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
<a href="../objects/kerning.html">Kerning objects</a> have an interpolation method as well. It is debateable whether an interpolation of two fonts should also automatically interpolate the kerning, so we picked the more explicit approach: in your interpolation script you have to do the interpolation of the kerning objects seperately.
|
|
</p>
|
|
|
|
<h2>Examples</h2>
|
|
|
|
<h3>Straight interpolating (either FontLab or UFO)</h3>
|
|
|
|
<p>
|
|
Setting a third font to an interpolation of two others.
|
|
</p>
|
|
|
|
<pre>
|
|
from robofab.world import OpenFont
|
|
minFont = OpenFont(pathToMinFont)
|
|
maxFont = OpenFont(pathToMaxFont)
|
|
# or any other way you like to get two font objects
|
|
|
|
inbetweenFont = OpenFont(pathToInbetweenFont)
|
|
# so now we have 3 font objects, right?
|
|
|
|
inbetweenFont.interpolate(.5, minFont, maxFont)
|
|
# presto, inbetweenFont is now 50% of one and 50% of the other
|
|
|
|
inbetweenFont.interpolate((.92, .12), minFont, maxFont)
|
|
# presto, inbetweenFont is now horizontally
|
|
# vertically interpolated in different ways.
|
|
</pre>
|
|
|
|
<h3>Interpolating two glyphs in the same font</h3>
|
|
|
|
<p>
|
|
For any number of reasons you might want to interpolate a glyph within the same font. Here's how to do it.
|
|
</p>
|
|
|
|
<pre>
|
|
from robofab.world import CurrentFont
|
|
f = CurrentFont()
|
|
g = f.newGlyph("interpolated")
|
|
g.interpolate(.5, f["a"], f["b"]
|
|
# if you're in fontlab:
|
|
g.update()
|
|
</pre>
|
|
|
|
<h2>Alternatives</h2>
|
|
<p>
|
|
These are the conventional ways of doing interpolation. Have a look at <a href="glyphmath.html">RoboFab's GlyphMath</a> for alternatives for blending and interpolating glyphs together.
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html> |