NAME
Font::GlyphNames - Convert between glyph names and characters
VERSION
Version .02
WARNING: This is a pre-alpha release. The API is subject to change without notice. Some of the features (those commented out in the synopsis) have not yet been implemented.
SYNOPSIS
use Font::GlyphNames qw[
name2str
name2code
str2name
code2name
code2ligname
];
name2str qw[one two three s_t Psi uni00D4];
# name2code qw[one two three s_t Psi uni00D4]
# str2name qw[1 2 3 st E<0x3A8> E<Ocirc>];
# code2name qw[49 50 51 115 116 936 212];
# code2ligname qw[49 50 51 115 116 936 212];
# Or you can use the OO interface:
use Font::GlyphNames;
$gn = new Font::GlyphNames; # use default glyph list
$gn = new Font::GlyphNames 'my-glyphs.txt'; # custom list
$gn->name2code(qw[ a slong_slong_i s_t.alt ]);
# etc.
DESCRIPTION
This module uses the Adobe Glyph Naming convention (see "SEE ALSO") for converting between glyph names and characters (or character codes).
METHODS/FUNCTIONS
Except for new
(which is only a method), each item listed here is both a function and a method.
- new ( LIST )
-
This class method constructs and returns a new Font::GlyphNames object. If an error occurs, it returns undef (check
$@
for the error; note also thatnew()
clobbers any existing value of$@
, whether there is an error or not). LIST is a list of files to use as a glyph list. If LIST is omitted, the Zapf Dingbats Glyph List and the Adobe Glyph List (see "SEE ALSO") will be used instead. - name2str ( LIST )
-
LIST is a list of glyph names. This function returns a list of the string equivalents of the glyphs in list context, or the string equivalent of the last item in scalar context. Invalid glyph names and names beginning with a dot (chr 0x2E) produce undef. Some examples (in list context):
name2str 's_t' # returns 'st' name2str qw/Psi uni00D4/ # returns ("\x{3a8}", "\xd4") name2str '.notdef' # returns undef name2str 'uni12345678' # returns "\x{1234}\x{5678}" name2str qw/one uni32 three/ # returns ('one', undef, 'three')
If, for invalid glyph names, you would like something other than undef (the null char, for instance), you can replace it afterwards easily enough:
map +("\0",$_)[defined], name2str ...
- name2code ( LIST )
- str2name ( LIST )
- code2name ( LIST )
- code2ligname ( LIST )
-
These have yet to be implemented.
THE GLYPH LIST FILE FORMAT
Note: This section is not intended to be normative. It simply describes how this module parses glyph list files--which works with those provided by Adobe.
All lines that consist solely of whitespace or that have a sharp sign (#) preceded only by whitespace (if any) are ignored. All others lines must consist of the glyph name followed by a semicolon, and the character numbers in hex, separated and optionally surrounded by whitespace. If there are multiple character numbers, the glyph is understood to represent a sequence of characters. The line breaks must be either CRLF sequences (as in Adobe's lists) or native line breaks. If a glyph name occurs more than once, the first instance will be used.
COMPATIBILITY
This module requires perl 5.8.0 or later. Though it should work in Windows, MacPerl, and any Unix flavour, I have only tested it in perl 5.8.6 on Mac OS X 10.4 (Darwin 8).
BUGS
name2str
does not properly validate glyph names consisting of "u" followed by five or six hex digits. Specifically, it lets surrogates (such as u0D800) and characters above U+10FFFF (e.g., u120000) through.
Please e-mail me if you find any other bugs.
AUTHOR
Father Chrysostomos <join '', name2str qw[s p r o u t at c p a n period o r g]>
SEE ALSO
- Unicode and Glyph Names
-
http://partners.adobe.com/public/developer/opentype/index_glyph.html
- Glyph Names and Current Implementations
-
http://partners.adobe.com/public/developer/opentype/index_glyph2.html
- Adobe Glyph List
-
http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt
- ITC Zapf Dingbats Glyph List
-
http://partners.adobe.com/public/developer/en/opentype/zapfdingbats.txt
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 309:
=over without closing =back