File Coverage

blib/lib/PostScript/DecodeGlyphName.pm
Criterion Covered Total %
statement 23 41 56.1
branch 6 12 50.0
condition n/a
subroutine 7 13 53.8
pod 2 2 100.0
total 38 68 55.8


line stmt bran cond sub pod time code
1 2     2   49454 use 5.008001;
  2         10  
  2         103  
2 2     2   16 use strict;
  2         4  
  2         97  
3 2     2   13 use warnings;
  2         3  
  2         171  
4              
5             package PostScript::DecodeGlyphName;
6             $PostScript::DecodeGlyphName::VERSION = '0.001';
7             # ABSTRACT: PostScript glyph name to Unicode conversion
8              
9 2     2   2891 use Exporter::Tidy all => [qw( decode_glyph parse_adobeglyphlist )];
  2         25  
  2         14  
10              
11 0     0   0 sub _croak { require Carp; goto &Carp::croak }
  0         0  
12              
13 2     2   218 sub _utf8ify { no warnings 'utf8'; map { pack "U", hex } @_ }
  2     11   5  
  2         1776  
  11         22  
  16         134  
14              
15             my $uni_notation = qr{
16             \A uni
17             (
18             (?:
19             [0-9ABCEF] [\dA-F] {3}
20             |
21             D [0-7] [\dA-F] {2}
22             )+
23             )
24             \z
25             }x;
26              
27             # this is a sexeger
28             my $u_notation = qr{
29             \A
30             (
31             [\dA-F] {2}
32             (?:
33             [0-7] D 0? 0?
34             |
35             [\dA-F] [\dABCEF] [\dA-F] {0,2}
36             )
37             )
38             u \z
39             }x;
40              
41             my %agl;
42              
43             sub decode_glyph {
44 32     32 1 18581 my $digits;
45 32 100       582 return join '', map {
    100          
    50          
46 32         72 exists $agl{ $_ }
47             ? $agl{ $_ }
48             : ( ( $digits ) = m/$uni_notation/ ) ? _utf8ify $digits =~ /(....)/g
49             : ( ( $digits ) = reverse =~ m/$u_notation/ ) ? _utf8ify scalar reverse $digits
50             : '';
51             }
52 32 50       115 map { split /_/ }
53 32         111 map { /\A(.+?)\./ ? $1 : $_ }
54 32         74 map { split } @_;
55             }
56              
57             sub parse_adobeglyphlist {
58 0     0 1   my ( $input_method, $data ) = @_;
59              
60             my %reader = (
61 0     0     array => sub { $_[0] },
62 0     0     data => sub { [ split /^/m, shift ] },
63 0     0     fh => sub { [ <$_[0]> ] },
64             file => sub {
65 0 0   0     open my $fh, '<', $_[0]
66             or _croak( "Error opening $_[0]: $!" );
67 0           [ <$fh> ];
68             },
69 0           );
70              
71 0 0         _croak( "No such input type '$input_method'" )
72             unless exists $reader{ $input_method };
73              
74 0           my $lines = $reader{ $input_method }->( $data );
75              
76 0           @$lines = grep !/\A \s* (?: \# | \z)/x, @$lines;
77              
78 0           chomp @$lines;
79              
80 0           %agl = map {
81 0           my ( $code_pt, $glyph ) = split /;/;
82 0           ( $glyph => _utf8ify $code_pt );
83             } @$lines;
84              
85 0           delete $agl{ '.notdef' };
86              
87 0           return 1;
88             }
89              
90             1;
91              
92             __END__