The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Font::TTF::Scripts::Volt - Memory representation of a Volt based font

SYNOPSIS

 use Font::TTF::Scripts::Volt;
 $fv = Font::TTF::Scripts::Volt->read_font($ttf_file, $ap_file, %opts);
 $dat = $fv->parse_volt;
 @map = $fv->align_glyphs($dat);
 $fv->merge_volt($dat, \@map);
 $fv->make_classes;
 $fv->make_anchors;
 $fv->make_groups;
 $fv->make_lookups;
 $res = $fv->out_volt;

DESCRIPTION

Font::TTF::Scripts::Volt is based on and inherits from Font::TTF::Scripts::AP and as such supports all the information and methods in such an object. The read method does little beyond calling the corresponding AP method.

The real power in this module is in the parse_volt that can parse Volt source code. It does it rather slowly, but it does do it and reads it into an internal data structure. This data structure can then be merged into an existing font using align_glyphs and merge_volt. From there it can be output as Volt source. The data structure representing the Volt source is a hash containing the following elements:

glyphs

Similar to the glyphs array from AP but adds a few Volt specific sub values

uni

A possibly empty array of Unicode scalar values (as decimal integers).

type

MARK, BASE (in VOLT UI this is the SIMPLE type), LIGATURE or COMPONENT. This element will not be defined if the VOLT type is UNASSIGNED.

component_num

Number of components in a ligature

name

Volt name in the source

anchors

An optional hash by anchor name that contains an array of anchor definitions, one anchor for each ligature component (non-ligature glyphs have a single element in the array). Each anchor definition is a hash including:

pos

A pos type containing the actual position of the anchor point

locked

Contains LOCKED if the anchor point is locked

scripts

A hash of script structures keyed off the script tag as used in Volt, containing:

name

Optional script name as in Volt

tag

Four letter script tag that ends up in the font

langs

An array of language structures consisting of (nearly there)

name

Optional language name as in Volt

tag

Four letter language tag that ends up in the font

features

Hash of feature structures keyed by feature tag, each containing (last one)

name

Optional name of the feature

tag

Four letter feature tag that ends up in the font

lookups

Array of names of lookups associated with this feature

groups

A hash of group definitions by name. The contents is an array of context_items corresponding to each element in the defining enum for the group.

lookups

An array of lookups in the order they appear in the Volt source. Each lookup consists of

id

Lookup name

base

Contains PROCESS_BASE if that is in the lookup

marks

Contains one of SKIP_MARKS, PROCESS_MARKS, or MARK_GLYPH_SET

all

Contains a group name or ALL according to what is to be processed

dir

Contains LTR or RTL

comment

Comment, if any, associated with the lookup; string value but can be multi-line.

contexts

Contains an array of contexts as per IN_CONTEXT. Each element of the array is itself an array corresponding to the elements in a context. The first element this array is a string IN_CONTEXT or EXCEPT_CONTEXT depending on the type of context. Subsequent elements are arrays that consist of two elements: A string LEFT or RIGHT and a context_item.

lookup

A two-element array, the first element giving the lookup type: sub or pos and the second element being the content of the lookup.

For a sub lookup the second element is an array each element of which is a substitution pair held in an array. The first element of this substitution pair is an array of context_items to be substituted and the second element is an array of context_items that the subsitutition is substituted with.

For a pos lookup, the second element is an array hashes, one per sublookup. The elements in the hash are dependent on the type of positioning but have consistent meaning:

type

The type of positioning. May be ATTACH, ATTACH_CURSIVE, ADJUST_SINGLE, ADJUST_PAIR.

context

Gives the context glyph for ATTACH and ADJUST_SINGLE lookups and consists of an array of context_items

first

The first context glyph for an ADJUST_PAIR. It consists of an array of context_items which are referenced by number according to their index (starting at 1) in the positioning.

second

The second context glyph for an ADJUST_PAIR. It consists of an array of contexts_items which correspond to the second number in a position.

exits

An array of context_items one for each glyph with an exit anchor. Used only in ATTACH_CURSIVE

enters

An array of context_items one for each glyph with an entry anchor. Used only in ATTACH_CURSIVE

to

Used in an ATTACH to specify what glyphs are being attached and with which anchor point. Each element of this array is an array with two elements: a context_item to specify the moving glyph(s) (the non-moving glyph is specified by the context hash entry) and the name of the anchor point used to link the two. The base glyph has an anchor with the anchor name and the second glyph has an anchor with the anchor named prefixed by MARK_

adj

An adjustment is used in a ADJUST_SINGLE as an array of positioning elements of type pos each one corresponding to a context_item in the context array.

For an ADJUST_PAIR the adj is an array of arrays. Each sub array has 3 elements: first index into the first array (starting at 1), second index into the second array (starting at 1) and a pos to specify the actual adjustment of those two glyphs.

info

The info hash contains some global information for the whole font with the following hash elements:

ppos

Specifies the pixesl per em for positioning purpsoes

grid

Specifies the pixels per em for the grid

pres

Specifies the presentation pixels per em

ppfmt2

Optional. If TRUE, then the project options request use of pair position format 2 (rather than the default of format 1).

cmap

An array of cmap entries, each of which is an array of 3 numbers.

In addition to extra entries in the main object there are two types that are used in various places:

context_item

A context_item consists of an array with two or three elements. The first, a string, gives the type of the context item and the subsequent elements give the value. The context types are:

GLYPH

The second array element contains a glyph id. Note it does not contain a glyph name. The name is resolved to an id in the parser and converted back to a name during output.

GROUP

The second array element is a string holding the name of the group being referenced

RANGE

The second and third array elements are the first and last glyph id for the range. Ranges are particularly difficult to work with when merging different glyph arrays so should be avoided

ENUM

An enum is a way of embedding a list of contexts within a context. The second array element is an array of context_items

Pos

A positioning element is a glorious animal. You would think that it could just be an x and y co-ordinate. You would be so wrong! A pos is a hash with three elements: x, y and adv. adv specifies changes to the advance width of a glyph in ADJUST_PAIR.

Each of these hash entries is an array. The first element of the array is the actual co-ordinate value. The second is an optionally empty array of adjustments to that co-ordinate. Each element of that array is a two element array of the adjust value and the ppem value at which the adjustment occurs.

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

Additional options available to this function include

-point2anchor

Reference to a function that parses an Attachment Point name and returns a list considting of a Volt anchor name and component number. The components should be numbered starting from 1. Special conditions that may be returned:

If the return value is undef, or if the anchor name is undef, then this attachment point is ignored.

If the returned component number is undef, 1 will be assumed.

If -point2anchor is not provided, a default function (see below) is used.

$fv->out_volt(%opts)

Assembles the VOLT project source and returns it as a multi-line string.

Options include

  -default_glyphtype  Glyphs whose C<type> is unknown get set to this type

$fv->parse_volt([$vtext])

Parses volt source. If no $vtext then take it from the TSIV table in the font.

$fv->normal_rules($ndrawn, \%opts)

Generate ligature lookup normal_rules based on Unicode composition rules. If $ndrawn is true, then add rules for all Unicode composites, otherwise only those composites whose glyph is an actual TrueType contour glyph.

Options: -force force new lookup even if it already exists.

$fv->make_lookups($ligtype, \%opts)

Construct substitution lookups for all classes and ligclasses, and position lookups for all lists. Options include

  -force   force new lookup even if it already exists.
  -notmark list of anchors that do not imply a MARK glyph (e.g. "_R")

$fv->make_groups

Convert all lists, classes and ligclasses into Volt groups.

$fv->make_anchors

Convert all attachment points in $fv into Volt anchors

point2anchor

This function, used if -point2anchor option isn't provided, peels off any digits at the end of the supplied Attachment Point name and uses them for the component. Anchor names starting with "_" are altered to start with "MARK_" instead.

NB: This function is not an object method, and it can be overridden by setting the -point2anchor option of read_font.

See also

Font::TTF::Scripts::AP

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.