Erik van Blokland 3646055ea2 initial import
git-svn-id: http://svn.robofab.com/trunk@1 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
2008-01-07 17:40:34 +00:00

84 lines
5.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<xml>
<include src="settings/generic.xml"/>
<synopsis
name="Building accents"
description="use RoboFab to build accented glyphs with components."
keywords="accent, howto, component"/>
<title>Building accents</title>
<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>
<pythonsource src="examples/usageBuildaccents.py"/>
<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>
<python type="output"><![CDATA[
Acircumflexdotaccent: A circumflex.top dotaccent.bottom
]]></python>
<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>
<pythonsource src="examples/buildaccentsBuilder.py"/>
<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>
<pythonsource src="examples/buildaccentsCustom.py"/>
</div>
</xml>