|
Font::GlyphNames - Convert between glyph names and characters |
Font::GlyphNames - Convert between glyph names and characters
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.
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.
=head1 DESCRIPTION
This module uses the Adobe Glyph Naming convention (see SEE ALSO) for converting between glyph names and characters (or character codes).
Except for new (which is only a method), each item listed
here is
both a function and a method.
$@ for the error; note
also that new() 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 '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 ...
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.
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).
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.
Father Chrysostomos <join '', name2str qw[s p r o u t at c p a n period o r g]>
|
Font::GlyphNames - Convert between glyph names and characters |