290 lines
9.6 KiB
HTML
290 lines
9.6 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>Building accents</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">
|
||
|
<a href="../objects/component.html">RComponent</a><br />
|
||
|
<a href="../objects/contour.html">RContour</a><br />
|
||
|
<a href="fontlabremote.html">FontLab Remote</a><br />
|
||
|
<a href="generatefonts.html">Generate Fonts</a><br />
|
||
|
<a href="index.html">How To</a><br />
|
||
|
<a href="lowlevel.html">How to get to FontLab stuff</a><br />
|
||
|
<a href="scripting.html">Scripting</a><br />
|
||
|
<a href="understandcontours.html">Understanding Contours</a><br />
|
||
|
<a href="usepens.html">Using Pens</a><br />
|
||
|
<a href="usethelib.html">Using the lib</a><br />
|
||
|
<a href="world.html">The world module</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-2005 RoboFab
|
||
|
<br />
|
||
|
version 1.1.1
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
<div class="content">
|
||
|
<h1>Building accents</h1>
|
||
|
|
||
|
|
||
|
<p>
|
||
|
Making accented glyphs is a job where scripting can help save some time. When you have prepared all the parts, the base glyphs and the accents, a script can help to assemble the combinations. There are various ways of doing it, let's start with a simple one.
|
||
|
</p>
|
||
|
<pre>
|
||
|
from robofab.world import CurrentFont
|
||
|
|
||
|
f = CurrentFont()
|
||
|
f.newGlyph("aacute")
|
||
|
f["aacute"].appendComponent("a")
|
||
|
f["aacute"].appendComponent("acute", (200, 0))
|
||
|
f["aacute"].width = f["a"].width
|
||
|
f.update()
|
||
|
</pre>
|
||
|
<p>
|
||
|
In this example the script creates a new glyph, <strong>aacute</strong>, then proceeds to add components, references to other glyphs rather than the glyphs themselves. The glyph method <strong>appendComponent</strong> is used to do this. See how the <strong>acute</strong> component has an extra argument, (200, 0) - this the offset for the accent. Finally the new glyph is given the width of the base <strong>a</strong>.
|
||
|
</p>
|
||
|
<p>
|
||
|
This example illustrates the use of the very basic <strong>appendComponent</strong> method. But it's not a very useful way to make glyphs. For instance, the string <strong>"aacute"</strong> could easily be made into a variable taken from a list. And dealing with the offsets when placing the accent isn't going to be efficient either when you want to make a large list of accented glyphs. How to go about it that?
|
||
|
</p>
|
||
|
|
||
|
<h2>Building accents automagically</h2>
|
||
|
<p>
|
||
|
RoboFab has its own database which connects glyphnames to components. In the RoboFab distribution folder, go to Data/GlyphConstruction.txt. This text file contains a list of glyphnames and from which components they should be built. The RoboFab Glyph Construction database was based on FontLab's glyph list. This list contains information about where components should be connected.
|
||
|
</p>
|
||
|
|
||
|
<pre>
|
||
|
Acircumflexdotaccent: A circumflex.top dotaccent.bottom
|
||
|
</pre>
|
||
|
|
||
|
<p>
|
||
|
This entry shows that Acircumflexdotaccent is constructed with components from A, a circumflex using the top anchor, and dotaccent using the bottom anchor.
|
||
|
</p>
|
||
|
|
||
|
<h2>Generate a glyph</h2>
|
||
|
<p>
|
||
|
RoboFab's Font object has several ways of starting component glyphs and adding stuff to them. There are different strategies possible for different kinds of problems.
|
||
|
</p>
|
||
|
|
||
|
<h3>font.generateGlyph(glyphName, replace, preflight, printErrors)</h3>
|
||
|
<p>
|
||
|
The easiest method to add an assembled glyph to a font is using the font's <strong>generateGlyph</strong> method. This will look for the glyphname in the glyph construction database and attempt to get all the components and place them at the anchors listed in the database. Let's have a look at its parameters.
|
||
|
<ul>
|
||
|
<li><strong>glyphName</strong>: the name of the glyph, has to correspond to a name in the glyph construction database.</li>
|
||
|
<li><strong>replace</strong>: default set to True, the new glyph will replace the old one if it exists.</li>
|
||
|
<li><strong>preflight</strong>: default set to False, preflight gives you the opportunity to run the glyph creation process without actually adding it to the font. This is useful if you're building the characterset and you don't have all the parts yet. Preflight will return a list of missing anchor points, missing accents, components, etc. Note that it can take several iterations of fixing problems and discovering new ones. If for instance a glyph for a componnent can't be found, it also means that some problems with that glyph are hidden. i.e. when a glyph "A" can't be found, preflight can't tell you that this glyph is missing a required anchor point either.</li>
|
||
|
<li><strong>printErrors</strong>: default set to True, print any errors and problems to the standard output window.</li>
|
||
|
</ul>
|
||
|
</p>
|
||
|
|
||
|
<h3>font.compileGlyph(glyphName, baseName, accentNames, adjustWidth=False, preflight=False, printErrors=True)</h3>
|
||
|
<p>
|
||
|
Compile a glyph with specified components. If you want to assemble accents that are not the glyph construction database, using compileGlyph.
|
||
|
|
||
|
<ul>
|
||
|
<li><strong>glyphName</strong>: the name of the glyph where it all needs to go.</li>
|
||
|
<li><strong>baseName</strong>: the name of the base glyph. accentNames: a list of accentName, anchorName tuples, [('acute', 'top'), etc]</li>
|
||
|
<li><strong>preflight</strong>: default set to False, preflight gives you the opportunity to run the glyph creation process without actually adding it to the font. This is useful if you're building the characterset and you don't have all the parts yet. Preflight will return a list of missing anchor points, missing accents, components, etc.</li>
|
||
|
<li><strong>printErrors</strong>: default set to True, print any errors and problems to the standard output window.</li>
|
||
|
</ul>
|
||
|
</p>
|
||
|
|
||
|
<h2>AccentBuilder</h2>
|
||
|
<p>
|
||
|
RoboFab comes with a versatile accent building tool, AccentBuilder. Have a look at robofab.tools.accentbuilder. AccentBuilder deals with components, anchorpoints.
|
||
|
</p>
|
||
|
|
||
|
<pre>
|
||
|
from robofab.accentBuilder import AccentTools, buildRelatedAccentList
|
||
|
font = CurrentFont
|
||
|
|
||
|
# a list of accented glyphs that you want to build
|
||
|
myList=['Aacute', 'aacute']
|
||
|
|
||
|
# search for glyphs related to glyphs in myList and add them to myList
|
||
|
myList=buildRelatedAccentList(font, myList)+myList
|
||
|
|
||
|
# start the class
|
||
|
at=AccentTools(font, myList)
|
||
|
|
||
|
# clear away any anchors that exist (this is optional)
|
||
|
at.clearAnchors()
|
||
|
|
||
|
# add necessary anchors if you want to
|
||
|
at.buildAnchors(ucXOffset=20, ucYOffset=40, lcXOffset=15, lcYOffset=30)
|
||
|
|
||
|
# print a report of any errors that occured
|
||
|
at.printAnchorErrors()
|
||
|
|
||
|
# build the accented glyphs if you want to
|
||
|
at.buildAccents()
|
||
|
|
||
|
# print a report of any errors that occured
|
||
|
at.printAccentErrors()
|
||
|
</pre>
|
||
|
|
||
|
|
||
|
<h2>Building your own accentbuilders</h2>
|
||
|
<p>
|
||
|
For typeface production it is a good idea to build a set of standardised tools with which you finalise the font data. Here's an example of a script which adds a standardised list of accents to a font. It does not do automatic anchor placement because the scripter wanted to do this manually. But the rest is done automatically. The script also deals correctly with smallcap glyphnames with .sc.
|
||
|
</p>
|
||
|
|
||
|
<pre>
|
||
|
|
||
|
# a script to generate all necessary accented characters.
|
||
|
# this assumes all anchor points are set correctly.
|
||
|
# including doublelayer accents. so, add anchorpoints on the accents too!
|
||
|
# (c) evb
|
||
|
|
||
|
from robofab.world import CurrentFont
|
||
|
from robofab.tools.toolsAll import readGlyphConstructions
|
||
|
|
||
|
f = CurrentFont()
|
||
|
|
||
|
import string
|
||
|
|
||
|
theList = [
|
||
|
# caps
|
||
|
'AEacute',
|
||
|
'AEmacron',
|
||
|
'Aacute',
|
||
|
'Abreve',
|
||
|
# add all the accents you want in this list
|
||
|
]
|
||
|
|
||
|
|
||
|
con = readGlyphConstructions()
|
||
|
theList.sort()
|
||
|
|
||
|
def accentify(f, preflight=False):
|
||
|
print 'start accentification', f.info.fullName
|
||
|
slots = con.keys()
|
||
|
slots.sort()
|
||
|
for k in theList:
|
||
|
if k[-3:] in [".sc"]:
|
||
|
isSpecial = True
|
||
|
tag = k[-3:]
|
||
|
name = k[:-3]
|
||
|
else:
|
||
|
isSpecial = False
|
||
|
tag = ""
|
||
|
name = k
|
||
|
parts = con.get(name, None)
|
||
|
if parts is None:
|
||
|
print k, "not defined?"
|
||
|
continue
|
||
|
base = parts[0]
|
||
|
accents = parts[1:]
|
||
|
f.generateGlyph(k, preflight=preflight)
|
||
|
f[k].mark = 100 + randint(-20, 20)
|
||
|
f[k].autoUnicodes()
|
||
|
f[k].update()
|
||
|
f.update()
|
||
|
|
||
|
accentify(f)
|
||
|
print 'done'
|
||
|
|
||
|
</pre>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|