File Coverage

blib/lib/PostScript/DecodeGlyphName.pm
Criterion Covered Total %
statement 22 40 55.0
branch 6 12 50.0
condition n/a
subroutine 7 13 53.8
pod 2 2 100.0
total 37 67 55.2


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