File Coverage

blib/lib/InfoBrief.pm
Criterion Covered Total %
statement 6 59 10.1
branch 0 22 0.0
condition 0 15 0.0
subroutine 2 7 28.5
pod 0 5 0.0
total 8 108 7.4


line stmt bran cond sub pod time code
1             #!/app/unido-i06/magic/perl
2             # -*- Mode: Perl -*-
3             # InfoBrief.pm --
4             # ITIID : $ITI$ $Header $__Header$
5             # Author : Ulrich Pfeifer
6             # Created On : Wed Dec 4 13:40:41 1996
7             # Last Modified By: Ulrich Pfeifer
8             # Last Modified On: Thu Jan 16 16:20:10 1997
9             # Language : CPerl
10             # Update Count : 79
11             # Status : Unknown, Use with caution!
12             #
13             # (C) Copyright 1996, Universität Dortmund, all rights reserved.
14             #
15             # $Locker$
16             # $Log$
17             #
18              
19             =head1 NAME
20              
21             InfoBrief - Perl extension for printing envelopes for Infobrief mailings according to the standards of the Deutsche Bundespost
22              
23             =head1 SYNOPSIS
24              
25             use InfoBrief;
26             $x = new InfoBrief %OPTIONS;
27             print $x->preamble;
28             print $x->page(@address);
29             print $x->trailer;
30              
31             =head1 DESCRIPTION
32              
33             This modules is probably not very useful outside of Germany. It is a
34             tool dedicated for printing envelopes for Infobrief mailings according
35             to the standards of the Deutsche Bundespost. You may customize it for
36             other standards though.
37              
38             The output generated is Postscript level 2 and conforms to EPSF 1.2.
39             Since C ist used, the single pages contain only the new
40             address and running number and the size of the postscript file is
41             modest.
42              
43             =head1 OPTIONS
44              
45             The Constructor C take a few options to customize the output:
46              
47             =over 5
48              
49             =item B
50              
51             =item B
52              
53             Generate A4 rsp. A5 output. Default is C5.
54              
55             =item B I
56              
57             =item B I
58              
59             Custom output size. Units are Postscript dots (72 dpi).
60              
61             =item B I
62              
63             Set custom border size. Default is C<20>.
64              
65             =item B I
66              
67             Set the Postamt for the "Entgelt bezahlt" stamp. Default is C<'44227
68             Dortmund 52'>.
69              
70             =item B
71              
72             Add/Omit the "Entgelt bezahlt" stamp. Default is C.
73              
74             =item B
75              
76             Add/Omit the "Infobrief" banner. Default is C since the banner
77             is not required.
78              
79             =item B
80              
81             Add/Omit a running number on each envelope. Default is C.
82              
83             =head1 AUTHOR
84              
85             Ulrich Pfeifer EFE
86              
87             =head1 SEE ALSO
88              
89             perl(1).
90              
91             =cut
92              
93             package InfoBrief;
94 1     1   993 use strict;
  1         2  
  1         43  
95 1     1   6 use vars qw($VERSION);
  1         2  
  1         1732  
96              
97             $VERSION = '0.14';
98              
99             my $POSTAMT = '44227 Dortmund 52';
100             my $STEMPEL;
101             my $PROLOG;
102             # a4 paper size
103             my $a4_width = 595;
104             my $a4_height = 842;
105             # a5 paper size
106             my $a5_width = $a4_height/2;
107             my $a5_height = $a4_width;
108             # c5 paper size
109             my $c5_width = 459;
110             my $c5_height = 649;
111              
112             # b5j paper size
113             my $b5j_width = 516;
114             my $b5j_height = 729;
115              
116             # b5 paper size
117             my $b5_width = 499;
118             my $b5_height = 708;
119              
120             # c6 paper size (309,613)
121             my $c6_width = 312;
122             my $c6_height = 624;
123              
124             my $border = 20;
125             my $width = $c5_width;
126             my $height = $c5_height;
127             my $s_s = 4; # scale stamp
128             my $stempel = 1; # stamp 'Gebühr bezahlt'
129             my $infobrief = 0; # banner 'Infobief'
130             my $numbering = 1; # running numbers?
131             {
132             # no strict;
133             local ($/) = "\n%--\n";
134             ($PROLOG, $STEMPEL) = ;
135             close DATA;
136             #$PROLOG =~ s/\$(\w+)/eval "\$$1"/eg;
137             }
138              
139             my @sender = (
140             'Fachbereich Informatik Lehrstuhl VI',
141             'UNIVERSITÄT DORTMUND',
142             'Aug.-Schmidt-Str. 12, 44221 Dortmund',
143             );
144              
145             sub preamble {
146 0     0 0   my $self = shift;
147 0           $self->{preamble};
148             }
149              
150             sub new {
151 0     0 0   my $type = shift;
152 0           my %parm = @_;
153 0           my $self = {};
154 0           my $date = `date`;
155 0           my $PROLOG = $PROLOG;
156              
157 0           chomp($date);
158              
159 0 0         if (exists $parm{a4}) {
    0          
    0          
    0          
160 0           $width = $a4_width;
161 0           $height = $a4_height;
162             } elsif (exists $parm{a5}) {
163 0           $width = $a5_width;
164 0           $height = $a5_height;
165             } elsif (exists $parm{b5}) {
166 0           $width = $b5_width;
167 0           $height = $b5_height;
168             } elsif (exists $parm{c6}) {
169 0           $width = $c6_width;
170 0           $height = $c6_height;
171             }
172 0   0       $self->{width} = $parm{width} || $width;
173 0   0       $self->{height} = $parm{height} || $height;
174 0   0       $self->{border} = $parm{border} || $border;
175 0   0       my $amt = $parm{amt} || $POSTAMT;
176 0   0       my $scale = $parm{scale} || $s_s;
177 0 0         $self->{numbering} =
    0          
178             ((exists $parm{numbering})?$parm{numbering}:$numbering)?'true':'false';
179 0 0         $self->{stempel} =
    0          
180             ((exists $parm{stempel})?$parm{stempel}:$stempel)?'true':'false';
181 0 0         $self->{infobrief} =
    0          
182             ((exists $parm{infobrief})?$parm{infobrief}:$infobrief)?'true':'false';
183 0           $PROLOG =~ s/\$(\w+)/$self->{$1}/g;
184              
185 0           my @sender = @sender;
186 0 0         if ($parm{sender}) {
187 0           @sender = @{$parm{sender}};
  0            
188             }
189 0           my ($SENDER,$line);
190 0           for ($line=0;$line<@sender;$line++) {
191 0           $SENDER .= "$line ($sender[$line]) Cshow\n";
192             }
193 0           $self->{'preamble'} = <
194             %!PS-Adobe-2.0 EPSF-1.2
195             %%Title: (FGIR Umschlaege)
196             %%Pages: (atend)
197             %%Creator: $0
198             %%CreationDate: $date
199             %%BoundingBox: 0 0 $self->{width} $self->{height}
200             %%Pages: (atend)
201             %%EndComments
202              
203             %%BeginProlog
204             $PROLOG
205             %%EndProlog
206              
207             %%BeginSetup
208             Rotate {
209             0 $width 2 mul translate
210             -90 rotate
211             } if
212             % a5 background
213             Background
214             {
215             gsave
216             newpath
217             0 0 moveto
218             $width $height Rechteck
219             0.95 setgray
220             fill
221             grestore
222             } if
223              
224             % STEMPEL
225             % P4 568 328
226              
227             gsave
228             328 $scale div $border add $height 568 $scale div $border add sub translate
229             90 rotate
230             gsave
231             568 $scale div 328 $scale div scale
232             $STEMPEL
233             grestore
234             17 18 moveto
235             Stempel {
236             /AvantGarde-Demi-ISO findfont 8 scalefont setfont
237             ($amt) show
238             } {
239             newpath
240             0 0 moveto
241             568 $scale div 328 $scale div Rechteck
242             1 setgray
243             fill
244             } ifelse
245             grestore
246             % LS6 Stempel
247             gsave
248             /AvantGarde-Demi-ISO findfont 9 scalefont setfont
249             %$border 3 mul $border 3 mul moveto
250             %90 rotate
251             $SENDER
252             grestore
253              
254             % INFOBRIEF
255             Infobrief {
256             gsave
257             /AvantGarde-Demi-ISO findfont 28 scalefont setfont
258             $border 3 mul $height 2 div (Infobrief) stringwidth pop 2 div sub moveto
259             90 rotate
260             (Infobrief) show
261             grestore
262             } if
263             %%EndSetup
264              
265             EOF
266             ;
267 0           $self->{page} = 0;
268 0           bless $self, $type;
269             }
270              
271             my %DEC = ("„" => "ä",
272             "" => "ü",
273             "”" => "ö",
274             '-' => "­",
275             "á" => "ß",
276             );
277              
278             my $DEC = join '|', keys %DEC;
279              
280             sub ps_string
281             {
282             # Prepare text for printing
283 0     0 0   local($_) = shift;
284 0           s/($DEC)/$DEC{$1}/eg;
  0            
285 0           s/[\\\(\)]/\\$&/g;
286 0           s/[\001-\037\177-\377]/sprintf("\\%03o",ord($&))/ge;
  0            
287 0           $_; # return string
288             }
289              
290             sub page {
291 0     0 0   my $self = shift;
292 0           $self->{page}++;
293 0           my $page = <
294             %%Page: $self->{page} $self->{page}
295             %Begin page
296              
297             gsave
298             newpath
299             Ax Ay moveto
300             150 250 $border add Rechteck
301             Background {0.95} {1.0} ifelse
302             setgray
303             fill
304              
305             % running number
306             Numbering {
307             newpath
308             $width $border 2 mul sub $border 2 mul moveto
309             30 30 Rechteck
310             Background {0.95} {1.0} ifelse
311             setgray
312             fill
313            
314             0 setgray
315             /AvantGarde-Demi-ISO
316             findfont 8 scalefont setfont
317            
318             $width $border 2 mul sub $border 2 mul moveto
319             ($self->{page}) show
320             } if
321              
322             0 setgray
323             FNAMEFONT
324              
325             EOP
326             ;
327 0           my $i;
328 0           for ($i=0;$i<@_;$i++) {
329 0           $page .= sprintf "%d (%s) Show\n", $i+1, ps_string($_[$i])
330             }
331 0           $page .= <
332             grestore
333             copypage
334             %End page
335             EOP
336             ;
337 0           $page;
338             }
339              
340             sub trailer {
341 0     0 0   my $self = shift;
342             <
343             %%Trailer
344             %%Pages: $self->{'page'}
345             EOT
346 0           ;
347             }
348              
349             __DATA__