Home

Contact Us

General

Initiative B@bel

WSI Guidelines

Encoding

Principles

Unicode

Training

Tutorials

PUA

Conversion

Resources

Utilities

TECkit

Maps

Resources

Input

Principles

Utilities

Tutorials

Resources

Type Design

Principles

Design Tools

Formats

Resources

Font Downloads

Gentium

Doulos

IPA

Rendering

Principles

Technologies

OpenType

Graphite

Resources

Font FAQ

Links

Glossary


Computers & Writing Systems

SIL HOME | SIL SOFTWARE | SUPPORT | DONATE

You are here: Type Design > Resources
Short URL: https://scripts.sil.org/FLGlyphBuilder

FLGlyphBuilder

Martin Hosken, Alan Ward, 2004-09-27

Table of Contents

Download

FLGlyphBuilder.py
Martin Hosken, Alan Ward, 2004-09-27
Download "FLGlyphBuilder.py", Python script, 19KB [1688 downloads]

Description

FLGlyphBuilder is a Python script for building composite glyphs in  FontLab. The composite glyphs can be built using attachment points and/or shifting of component glyphs. Using attachment points, composites are assembled by describing which attachment points should coincide, rather than having to give absolute locations in terms of shifting. Within FontLab, attachment points are created as anchors on specific glyphs. The constructed composites inherit attachment points from their components. FLGlyphBuilder is controlled by a composite definition file. This XML file contains the following key elements:

Composite Definition File

glyph

This describes a glyph and the attributes allow setting of the name and Unicode id for the glyph. The glyph element has children which describe what goes into the glyph.

The "overstrike" attribute controls whether an attachment to a base glyph can extend beyond the origin or the advance width of the base glyph. The default is set by the default_overstrike global variable (see below). Set to 1 to allow attached glyphs to extend to the left of origin or to the right of advance. Set to 0 to shift attached glyphs right and increase advance so overstriking of adjacent glyphs does not happen.

base

A base character is a reference to a glyph via Unicode id, postscript name, or glyph id which is used in building the composite glyph. If there is more than one base glyph in a composite glyph, then the base glyphs are concatenated in sequence according to their advance widths.

attach

A base glyph may have attachments (eg diacritics), which may have their own attachments in their turn. The "attach" element has two attributes which name the attachment point on the base ("at") and the attachment point on the diacritic ("with") which are used for positioning so that the attachment points coincide. If these are missing, then the glyphs are aligned centrally in the x direction and with no adjustment vertically.

shift

It is also possible to shift base and attach glyphs. Shifting occurs after attachment (for obvious reasons) if both are used together.

Here is a sample composite definition XML file:

<?xml version="1.0"?>
<font>
    <glyph PSName="LtnSmA.Sup">
         <base PSName="LtnSupSmA"/>
    </glyph>
    <glyph PSName="LtnSmAAcute" UID="00E1">
         <base PSName="LtnSmA">
             <attach PSName="CombAcute" with="_U" at="U"/>
         </base>
    </glyph>
    <glyph PSName="LtnSmACircumAcute" UID="1EA5">
        <base PSName="LtnSmA">
            <attach PSName="CombCircum" with="_U" at="U">
                <attach PSName="CombAcute" with="_U" at="U"/>
            </attach>
        </base>
    </glyph>
    <glyph PSName="SmRomNumTwo" UID="2171">
         <base PSName="LtnSmI"/>
         <base PSName="LtnSmI"/>
    </glyph>
    <glyph PSName="GrSubSmBeta" UID="1D66">
        <base PSName="ModSmBeta">
            <shift x="0" y="-1256"/>
        </base>
    </glyph>
</font>

The DTD is below.

Usage

FLGlyphBuilder works with anchors in the FontLab glyphs. Thus a designer adds an attachment point to a glyph by adding an anchor into the glyph design in Fontlab.

FLGlyphBuilder has several global variables which should be set before it is ran within the FontLab macro window. Below is a description of these variables. See the script file for more details.

ctlfile

This may be set to the actual composite definition file to use, otherwise setting it to None will cause the composite definition file to be built from the font filename with the fileext.

fileext

The composite definition file name is assumed to be the same as the fontlab filename minus its .vfb extension and with this value appended.

logfile

Logging information is output to this file or the screen if set to None.

stoplist1

A file containing a list of glyphs in the ctlfile that should not be created by FLGlyphBuilder. Used to handle composite glyphs that need manual adjustment of compoment placement or inherited attachment points. Can be set to None so all glyphs in the ctlfile are built to create drafts, then set to a file name to prevent rebuilding so manual adjustments can be safely applied.

The stoplist contains a list of glyph names. Comments can be added if the beginning of a line is #. Blank lines are allowed. An example is below.

stoplist2

Another file containing a stop list used as above.

stoplist1 can be used for problem composites in all faces while stoplist2 can be used for problem composites in a particular face.

default_overstrike

Controls whether overstrike guarding occurs by default or not. Sets the default value for the overstrike attribute on the glyph element (see above).

safety

This variable controls what happens if a glyph is created that already exists in the font. The variable can take any of these values:

  • 0 - simply replace with no comment
  • 1 - replace but comment that something happened in the log
  • 2 - if the original glyph is a compound, replace it, otherwise rename it with a __ prefix
  • 3 - if the original glyph is a compound, replace it, otherwise don't replace the glyph, give an error in the log instead
  • 4 - always rename the original glyph with a ___ prefix
  • 5 - always give an error in the log and don't replace the glyph

behaviour

Controls various aspects of the behaviour of FLGlyphBuilder. This is a bit field with each bit position having a meaning.

  • bit 0 - remove used attachment points on the base glyph
  • bit 1 - build single component composite glyphs. Otherwise glyphs of this type in the ctlfile are skipped. Set the bit to 1 to create draft glyphs. Set the bit to 0 to disable rebuilding these glyphs so they can safely be manually adjusted.

debug

This is a bitfield value that controls what information will be output during the process, primary for debugging purposes.

  • bit 0 - Show XML hierarchy
  • bit 1 - Show component positioning calculatins
  • bit 2 - Show components added to glyphs

verbosity

Control what information is output to the log

  • 0 - output error messages only
  • 1 - output progress messages
  • 2 - add extra information

colors

This is a hash of color values to use for different types of glyph. See FLGlyphBuilder.py for details.

srcfnt

Fontlab object that constitutes the source font. Defaults to the current font.

dstfnt

Fontlab object in which to create new glyphs. Defaults to the current font but may be another font, to create a new font or add glyphs to another font.

Here is a sample stop list:

# Ogonek moved to match curve of o
LtnSmOOgonekMacron

# U moved up
LtnSmOOgonekMacron
LtnSmAeMacron
LtnCapADotAbvMacron

The DTD for the composite definition file is:

<!ELEMENT font (glyph)+>

<!ELEMENT glyph (base)+>
<!ATTLIST glyph
PSName CDATA #IMPLIED
UID    CDATA #IMPLIED
GID    CDATA #IMPLIED
overstrike (0 | false | 1 | true )  #IMPLIED>

<!ELEMENT base (attach | shift)*>
<!ATTLIST base
PSName CDATA #IMPLIED
UID    CDATA #IMPLIED
GID    CDATA #IMPLIED>

<!ELEMENT attach (shift)*>
<!ATTLIST attach
PSName CDATA #IMPLIED
UID    CDATA #IMPLIED
GID    CDATA #IMPLIED
with   CDATA #IMPLIED
at     CDATA #IMPLIED>

<!ELEMENT shift EMPTY>
<!ATTLIST shift
x CDATA #IMPLIED
y CDATA #IMPLIED>

History

The original FLGlyphBuilder was (and is) a Perl script which works directly on TrueType font (ttf) files. The script on this page is a rewrite for FontLab in Python. It supports only a subset of the features of the Perl version. The Perl ttfbuilder package is available on CPAN  Perl TTFBuilder. Consult that script for the definitive format for the XML composite definition file. The name of the Perl script may be changed to GlyphBuilder in the future. Thanks to Martin Hosken for creating the intial version of FLGlyphBuilder.



Note: If you want to add a response to this article, you need to enable cookies in your browser, and then restart your browser.

Note: the opinions expressed in submitted contributions below do not necessarily reflect the opinions of our website.



© 2003-2019 SIL International, all rights reserved, unless otherwise noted elsewhere on this page.
Provided by SIL's Writing Systems Technology team (formerly known as NRSI). Contact us here.