Bob Hallissy
and 1 contributors

NAME

Font::TTF::Scripts::AP - Memory representation of a TTFBuilder Attachment Point database (APDB)

SYNOPSIS

 use Font::TTF::Scripts::AP;
 $ap = Font::TTF::Scripts::AP->read_font($ttf_file, $ap_file, %opts);
 $ap->make_classes();

INSTANCE VARIABLES

cmap

Reference to the Microsoft cmap within the font.

font

Reference to a font structure. read_font will cause at least the post, cmap, loca, and name tables to be read in.

glyphs

An array of references to glyph data structures, indexed by glyphID. Stucture elements are:

uni

Array of Unicode scalar values (decimal integers), if any, that map from cmap to this glyph.

gnum

Actual glyph ID from font.

post

Actual Postscript name from font.

name

This element is set by "make_names" or "make_classes" and is the replacement name returned by "make_name".

Note: The uni, gnum and post values are based on the UID, GID, and PSName fields of the APDB. If there are descrepancies between the APDB and the font's internal tables, then for calcuating the above three values, priority is given first to UID field, then PSName field, and finally GID.

glyph

Reference to glyph structure read from font.

line

Line number in APDB where glyph is defined.

points

A hash of references to attachment point structures for this glyph, keyed by attachment point type (aka name). Each AP structure contains

name

The name (type in TTFBuilder terminology) of the attachment point

x, y

X and Y coordinates for the attachment point

line

Line number in APDB where this point is defined.

components

Present if the glyph is a composite. Is a reference to an array of component structures. Each component structure includes:

bbox

comma separated list of bounding box coordinates, i.e., x1, y1, x2, y2

uni

Unicode scalar value, if any, of the component. (decimal integer)

line

Line number in APDB where this component is defined.

Note: The following instance variables contain the actual text read from the APDB. If there are descrepancies between the APDB and the font, these values may differ from corresponding values given above. Therefore these values should not be used except for diagnostic purposes.

UID

Unicode scalar value, if any, as specified in the APDB. (string of hex digits)

PSName

Postscript name, if any, as specified in the APDB

GID

Glyph id, if any, as specified in the APDB

classes

Created by "make_classes", this is a hash keyed by class name returning an array of GIDs for glyphs that are in the class. Classes are identified by extensions (part after a '.') on the post name of each glyph. For each such extension, two classes are defined. The first is the class of all glyphs that have that extension (class name is the extension). The second is the class of nominal glyphs corresponding to the glyphs with that extension (class name is the extension but with the prefix 'no_').

lists

Created by "make_classes", this is a hash keyed by attachment point name (as modified by "make_point") returning an array of GIDs for glyphs that have the given attachment point.

vecs

If defined, this variable will be updated by "make_classes". It is a hash, keyed by attachment point name (as modified by "make_point") returning a bit vec bit array, indexed by GID, each bit set to 1 if the corresponding glyph has the given attachment point.

ligclasses

Optionally created by "make_classes" if ligatures are requested and they exist. The base forms class is no_code while the ligatures are held in code.

WARNINGS

If -errorfh not set, this accumulates any warning or error messages encountered.

cWARNINGS

Count of number of warnings or errors encountered.

METHODS

$ap = Font::TTF::Scripts::AP->read_font ($ttf_file, $ap_file, %opts)

Reads the TrueType font file $ttf_file and the attachment point database (APDB) file $ap_file, and builds a structure to represent the APDB.

Options that may be supplied through the %opts hash include:

-omittedAPs

A list of attachment point types to ignore. Can be a string containing comma- or space-separated names, or a ref to an array of strings.

-strictap

If true, warn about attachment points that do not correspond to appropriate points on the outline of the glyph.

-knownemptyglyphs

If this option is specified, read_font will warn if glyphs that should have outlines don't. The option value should be a list of names of glyphs that are known to have no outline (thus shouldn't generate warning). Can be a string containing comma- or space-separated names, or a ref to an array of strings.

-errorfh

A file handle to which warning messages are to be printed. If not supplied, warning messages are accumulated in WARNINGS.

$ap->add_classfile ($fname, %opts)

Reads the given xml classes description file and stores the info in this ap structure

$ap->make_names

An alternative to "make_classes", this method just creates name records for all the glyphs in the font. That is, for every glyph record in glyphs, "make_names" invokes "make_name" and saves the result in the name element of the glyph.

$ap->make_classes (%opts)

First, for every glyph record in glyphs, make_classes invokes make_name followed by, for every attachment point record in points, make_point . This gives sub-classes a chance to convert the names (of glyphs and points) to an alternate form (e.g., as might be useful in building Graphite source.) See GDL.pm for an example.

make_classes then builds the classes and lists instance variables, and updates the vecs instance variable (if it is defined).

Options supported are:

-ligatures

Accepts one of two possible values: 'first' or 'last'. First creates ligature classes with the class based on the first element of the ligature and the contents of the class on the rest of the ligature. Last creates classes based on the last element of the ligature, thus grouping all glyphs with the same last ligature element together. Ligature classes are stored in $self-{'ligclasses'}>.

Ligature elements are separated by _ in the glyph name. Ligatures are only made if there are corresponding non ligature glyphs in the font. A final .text on the glyph name of a ligature is assumed to be associated with the whole ligature and not just the last element.

-ligtype

If set to 'comp', then treat glyph name extension as part of the final element.

$ap->make_name ($gname, $uni, $glyph)

Given a glyph's name, USV, and a reference to its glyph structure, returns a replacement name, e.g., one that might be an acceptable identifier in a programming language. By default this returns $gname, but the function could be overridden when subclassing.

$ap->make_point ($pname, $glyph, \%opts)

Given an an attachment point name and a reference to its glyph structure, returns a replacement name, e.g., one that might be an acceptable identifier in a programming language, or undef to indicate the attachment point should be omitted. By default this returns $pname, but the function could be overridden when subclassing.

$opts->{'-ignoredAPs'} can be set to a list of AP names that should be ignored.

$fv->align_glyphs($dat)

Provides one possible way to map glyph names in a new font with an existing project.

Compares the list of glyphs found during "read_font" (the new glyph list) with the list from "parse_volt" in $dat (the old glyph list>, returning an array that provides a mapping between old and new glyph IDs. The array is indexed by old glyph ID and returns the new glyph ID.

This implementation works by sdiffing the two ordered lists of glyph names and then matching them up, first by name then by uni.

canon($psname)

Returns a canonical form of the given name in a form that is not useful for anythin except comparison

$str = $ap->as_xml()

Returns an XML representation of the AP database

See also

TTFBuilder, Font::TTF::Font

AUTHOR

Martin Hosken http://scripts.sil.org/FontUtils.

LICENSING

Copyright (c) 1998-2016, SIL International (http://www.sil.org)

This module is released under the terms of the Artistic License 2.0. For details, see the full text of the license in the file LICENSE.