blib/lib/PostScript/PseudoISO.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 53 CC 6 SCAR 34.7
CC
6
Cov
0%
prepstr
42.0
reencodingvector
2.0
BEGIN
2.0
CRAP 32.0
1 # PseudoISO.pm --
2 # RCS Info : $Id: PseudoISO.pm,v 1.3 2002-04-25 10:18:33+02 jv Exp $
3 # Author : Johan Vromans
4 # Created On : Tue Jun 20 17:07:38 2000
5 # Last Modified By: Johan Vromans
6 # Last Modified On: Thu Apr 25 10:18:20 2002
7 # Update Count : 36
8 # Status : Unknown, Use with caution!
9  
10 package PostScript::PseudoISO;
11  
12 $VERSION = "1.00";
13  
14 use strict;
15  
16 =head1 NAME
17  
18 PostScript::PseudoISO - Module with handy ISO enhancements
19  
20 =head1 SYNOPSYS
21  
22 $str = "This is an emdash: ---";
23 # Encode
24 $t = PostScript::PseudoISO::->prepstr($str);
25  
26 =head1 DESCRIPTION
27  
28 This module contains some handy extensions to PostScript ISO Latin1
29 encoding (ISO 8859.1).
30  
31 The (class) routine C<prepstr> massages a string and makes the
32 following changes, if appropriate:
33  
34 =over 4
35  
36 =item *
37  
38 Any sequence of whitespace characters is compressed into a single
39 space. To retain spaces, use characters with ocal code 240 which will
40 be turned into ordinary spaces but not compressed.
41  
42 =item *
43  
44 Any sequence of three consecutive periods will be changed to render an
45 ellipses.
46  
47 =item *
48  
49 Any sequence of three consecutive dashes will be changed to render an
50 em-dash.
51  
52 =item *
53  
54 Any sequence of two consecutive dashes will be changed to render an
55 en-dash.
56  
57 =item *
58  
59 Straight quotes C<"> and C<'> will be changed to render curly quotes.
60  
61 =back
62  
63 =head1 CLASS METHODS
64  
65 =head2 prepstr
66  
67 Example:
68  
69 $str = PostScript::PseudoISO::->prepstr ("emdash '---'");
70  
71 This routine makes the changes as described above.
72  
73 =head2 reencodingvector
74  
75 Example:
76  
77 $vec = PostScript::PseudoISO::->reencodingvector;
78  
79 This function returns a reference to a hash that contains the mapping
80 of glyphs that are not part of the ISO Latin1 encoding. This vector
81 can be used with the C<reencode> method of a
82 C<PostScript::BasicTypesetter> object.
83  
84 =cut
85  
86 sub prepstr {
87 my $self = shift;
88  
89 # Re-encode a string to (pseudo-)ISO.
90  
91 local ($_) = @_;
92 my $res = '';
93 my $chr;
94  
95 # Compress multiple blanks.
96 s/\s+/ /g;
97  
98 # Handle hard spaces.
99 s/\240/ /g;
100  
101 # Handle ellipsis.
102 s/(^|[^.])\.\.\.([^.]|$)/$1\200$2/g;
103  
104 # Handle em-dash.
105 s/(^|[^-])---([^-]|$)/$1\205$2/g;
106  
107 # Handle en-dash.
108 s/(^|[^-])--([^-]|$)/$1\211$2/g;
109  
110 # Handle (pseudo-)quotes.
111 while ( /^(.*?)([\"\'])(.*)$/s ) {
112  
113 $res .= $1; # before
114 $chr = $2; # the match
115 $_ = $+; # after
116  
117 # Quotes.
118 if ( $chr eq '"' ) {
119 # Open quote after space, [ and (; otherwise close quote.
120 $res .= ($res eq '' || $res =~ /[ (\[]$/) ? "\204" : "\202";
121 }
122 elsif ( $chr eq "'" ) {
123 # Sometimes apostrophe.
124 if ( /^(s-|s |t )/ ) { # 's-Gravenhage, 't, 's nachts
125 $res .= "'";
126 }
127 else {
128 # Open quote after space, [ and (; otherwise close quote.
129 $res .= ($res eq '' || $res =~ /[ (\[]$/) ? "`" : "'";
130 }
131 }
132 }
133  
134 $res . $_; # return
135 }
136  
137 my $reencodingvector;
138 sub reencodingvector {
139 my $self = shift;
140 $reencodingvector = {
141 "\200" => "ellipsis",
142 # "\201" => "quotesingright",
143 "\202" => "quotedblright",
144 # "\203" => "quotesingleft",
145 "\204" => "quotedblleft",
146 "\205" => "emdash",
147 "\206" => "quotesingle",
148 "\207" => "quotedouble",
149 "\210" => "bullet",
150 "\211" => "endash",
151 };
152  
153 }
154  
155 1;
156  
157 __END__