API2/Lite.pm

filter: Statementstmt 29.5% 49 / 166 Branchbran 21.4% 3 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 27.4% 14 / 51 Podpod 97.6% 41 / 42 totaltotal 37.1% 107 / 288 SCAR 42.0
CC
12
Cov
28%
saveas
36.0
print
12.0
text
6.0
CRAP 66.8
« API2/Resource/Glyphs.pm ↑ Summary API2/Resource/UniFont.pm »
1 package PDF::API2::Lite;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '2.044'; # VERSION
7  
8 BEGIN {
9  
10 2 ▶ use PDF::API2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶ use PDF::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶ use PDF::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶ use POSIX qw( ceil floor );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶ use vars qw( $hasWeakRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
18  
19 }
20  
21 =head1 NAME
22  
23 PDF::API2::Lite - (do not use)
24  
25 =head1 SYNOPSIS
26  
27 $pdf = PDF::API2::Lite->new;
28 $pdf->page(595,842);
29 $img = $pdf->image('some.jpg');
30 $font = $pdf->corefont('Times-Roman');
31 $font = $pdf->ttfont('TimesNewRoman.ttf');
32  
33 =head1 DESCRIPTION
34  
35 This class is unmaintained (since 2007) and should not be used in new code. It
36 combines many of the methods from L<PDF::API2> and L<PDF::API2::Content> into a
37 single class but isn't otherwise any easier to use.
38  
39 There have been many improvements and clarifications made to the rest of the
40 distribution that aren't reflected here, so the term "Lite" no longer applies.
41 It remains solely for compatibility with existing legacy code.
42  
43 =head1 METHODS
44  
45 =over
46  
47 =item $pdf = PDF::API2::Lite->new
48  
49 =cut
50  
51 sub new {
52 3 ▶ my $class=shift(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
53 3 my %opt=@_;
54 3 my $self={};
55 3 bless($self,$class);
56 3 $self->{api}=PDF::API2->new(@_);
57 3 return $self;
58 }
59  
60 =item $pdf->page
61  
62 =item $pdf->page $width,$height
63  
64 =item $pdf->page $llx, $lly, $urx, $ury
65  
66 Opens a new page.
67  
68 =cut
69  
70 sub page {
71 1 ▶ my $self=shift;
Subroutine page: called CC=2 SCAR=7.0
Pod documented
72 1 $self->{page}=$self->{api}->page;
73 1 ▶ $self->{page}->mediabox(@_) if($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 1 1
74 1 $self->{gfx}=$self->{page}->gfx;
75 # $self->{gfx}->compressFlate;
76 1 return $self;
77 }
78  
79  
80 =item $pdf->mediabox $w, $h
81  
82 =item $pdf->mediabox $llx, $lly, $urx, $ury
83  
84 Sets the global mediabox.
85  
86 =cut
87  
88 sub mediabox {
89 1 ▶ my ($self,$x1,$y1,$x2,$y2) = @_;
Subroutine mediabox: called CC=2 SCAR=7.4
Pod documented
90 1 ▶ if(defined $x2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $x2) { } 0 1 1
91 0 $self->{api}->mediabox($x1,$y1,$x2,$y2);
92 } else {
93 1 $self->{api}->mediabox($x1,$y1);
94 }
95 1 $self;
96 }
97  
98 =item $pdf->saveas $file
99  
100 Saves the document (may not be modified later) and
101 deallocates the pdf-structures.
102  
103 =cut
104  
105 sub saveas {
106 1 ▶ my ($self,$file)=@_;
Subroutine saveas: called CC=7 SCAR=35.8
Pod documented
107 1 ▶ if($file eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq '-') { } 1 0 1
108 1 return $self->{api}->to_string();
109 } else {
110 0 $self->{api}->save($file);
111 0 return $self;
112 }
113 0 foreach my $k (keys %{$self}) {
114 0 ▶ if(blessed($k) and $k->can('release')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($k) and $k->can('release')) { } 0 0 0
elsif (builtin::blessed($k) and $k->can('end')) { } 0 0 0
Condition0%0/3
builtin::blessed($k) and $k->can("release")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($k) and $k->can("release")
builtin::blessed($k) $k->can("release")
Truth table0%0/3
A and B
A= builtin::blessed($k)B= $k->can("release")
ABresult
0X0
100
111
115 0 $k->release(1);
116 ▶ } elsif(blessed($k) and $k->can('end')) {
Condition0%0/3
builtin::blessed($k) and $k->can("end")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($k) and $k->can("end")
builtin::blessed($k) $k->can("end")
Truth table0%0/3
A and B
A= builtin::blessed($k)B= $k->can("end")
ABresult
0X0
100
111
117 0 $k->end;
118 }
119 0 $self->{$k}=undef;
120 0 delete($self->{$k});
121 }
122 0 return;
123 }
124  
125  
126 =item $font = $pdf->corefont $fontname
127  
128 Returns a new or existing adobe core font object.
129  
130 B<Examples:>
131  
132 $font = $pdf->corefont('Times-Roman');
133 $font = $pdf->corefont('Times-Bold');
134 $font = $pdf->corefont('Helvetica');
135 $font = $pdf->corefont('ZapfDingbats');
136  
137 =cut
138  
139 sub corefont {
140 4 ▶ my ($self,$name,@opts)=@_;
Subroutine corefont: called CC=1 SCAR=0.0
Pod documented
141 4 my $obj=$self->{api}->corefont($name,@opts);
142 4 return $obj;
143 }
144  
145 =item $font = $pdf->ttfont $ttfile
146  
147 Returns a new or existing truetype font object.
148  
149 B<Examples:>
150  
151 $font = $pdf->ttfont('TimesNewRoman.ttf');
152 $font = $pdf->ttfont('/fonts/Univers-Bold.ttf');
153 $font = $pdf->ttfont('../Democratica-SmallCaps.ttf');
154  
155 =cut
156  
157 sub ttfont {
158 0 ▶ my ($self,$file,@opts)=@_;
Subroutine ttfont: not called CC=1 SCAR=6.9
Pod documented
159 0 return $self->{api}->ttfont($file,@opts);
160 }
161  
162 =item $font = $pdf->psfont($ps_file, [%options])
163  
164 Returns a new type1 font object.
165  
166 B<Examples:>
167  
168 $font = $pdf->psfont('TimesRoman.pfa', -afmfile => 'TimesRoman.afm', -encode => 'latin1');
169 $font = $pdf->psfont('/fonts/Univers.pfb', -pfmfile => '/fonts/Univers.pfm', -encode => 'latin2');
170  
171 =cut
172  
173 sub psfont {
174 0 ▶ my ($self,@args)=@_;
Subroutine psfont: not called CC=1 SCAR=6.9
Pod documented
175 0 return $self->{api}->psfont(@args);
176 }
177  
178 #=item @color = $pdf->color $colornumber [, $lightdark ]
179 #
180 #=item @color = $pdf->color $basecolor [, $lightdark ]
181 #
182 #Returns a color.
183 #
184 #B<Examples:>
185 #
186 # @color = $pdf->color(0); # 50% grey
187 # @color = $pdf->color(0,+4); # 10% grey
188 # @color = $pdf->color(0,-3); # 80% grey
189 # @color = $pdf->color('yellow'); # yellow, fully saturated
190 # @color = $pdf->color('red',+1); # red, +10% white
191 # @color = $pdf->color('green',-2); # green, +20% black
192 #
193 #=cut
194 #
195 #sub color {
196 # my $self=shift @_;
197 # return $self->{api}->businesscolor(@_);
198 #}
199  
200 =item $egs = $pdf->create_egs
201  
202 Returns a new extended-graphics-state object.
203  
204 B<Examples:>
205  
206 $egs = $pdf->create_egs;
207  
208 =cut
209  
210 sub create_egs {
211 1 ▶ my ($self)=@_;
Subroutine create_egs: called CC=1 SCAR=0.0
Pod documented
212 1 return $self->{api}->egstate;
213 }
214  
215 =item $img = $pdf->image_jpeg $file
216  
217 Returns a new jpeg-image object.
218  
219 =cut
220  
221 sub image_jpeg {
222 0 ▶ my ($self,$file)=@_;
Subroutine image_jpeg: not called CC=1 SCAR=6.9
Pod documented
223 0 return $self->{api}->image_jpeg($file);
224 }
225  
226 =item $img = $pdf->image_png $file
227  
228 Returns a new png-image object.
229  
230 =cut
231  
232 sub image_png {
233 0 ▶ my ($self,$file)=@_;
Subroutine image_png: not called CC=1 SCAR=6.9
Pod documented
234 0 return $self->{api}->image_png($file);
235 }
236  
237 =item $img = $pdf->image_tiff $file
238  
239 Returns a new tiff-image object.
240  
241 =cut
242  
243 sub image_tiff {
244 0 ▶ my ($self,$file)=@_;
Subroutine image_tiff: not called CC=1 SCAR=6.9
Pod documented
245 0 return $self->{api}->image_tiff($file);
246 }
247  
248 =item $img = $pdf->image_pnm $file
249  
250 Returns a new pnm-image object.
251  
252 =cut
253  
254 sub image_pnm {
255 0 ▶ my ($self,$file)=@_;
Subroutine image_pnm: not called CC=1 SCAR=6.9
Pod documented
256 0 return $self->{api}->image_pnm($file);
257 }
258  
259 =item $pdf->savestate
260  
261 Saves the state of the page.
262  
263 =cut
264  
265 sub savestate {
266 0 ▶ my $self=shift @_;
Subroutine savestate: not called CC=1 SCAR=6.9
Pod documented
267 0 $self->{gfx}->save;
268 }
269  
270 =item $pdf->restorestate
271  
272 Restores the state of the page.
273  
274 =cut
275  
276 sub restorestate {
277 0 ▶ my $self=shift @_;
Subroutine restorestate: not called CC=1 SCAR=6.9
Pod documented
278 0 $self->{gfx}->restore;
279 }
280  
281 =item $pdf->egstate $egs
282  
283 Sets extended-graphics-state.
284  
285 =cut
286  
287 sub egstate {
288 0 ▶ my $self=shift @_;
Subroutine egstate: not called CC=1 SCAR=6.9
Pod documented
289 0 $self->{gfx}->egstate(@_);
290 0 return($self);
291 }
292  
293 =item $pdf->fillcolor $color
294  
295 Sets fillcolor.
296  
297 =cut
298  
299 sub fillcolor {
300 0 ▶ my $self=shift @_;
Subroutine fillcolor: not called CC=1 SCAR=6.9
Pod documented
301 0 $self->{gfx}->fillcolor(@_);
302 0 return($self);
303 }
304  
305 =item $pdf->strokecolor $color
306  
307 Sets strokecolor.
308  
309 B<Defined color-names are:>
310  
311 aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, black, blanchedalmond,
312 blue, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflowerblue,
313 cornsilk, crimson, cyan, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, darkgrey,
314 darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon,
315 darkseagreen, darkslateblue, darkslategray, darkslategrey, darkturquoise, darkviolet,
316 deeppink, deepskyblue, dimgray, dimgrey, dodgerblue, firebrick, floralwhite, forestgreen,
317 fuchsia, gainsboro, ghostwhite, gold, goldenrod, gray, grey, green, greenyellow, honeydew,
318 hotpink, indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon,
319 lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgray, lightgreen, lightgrey,
320 lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightslategrey,
321 lightsteelblue, lightyellow, lime, limegreen, linen, magenta, maroon, mediumaquamarine,
322 mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen,
323 mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, navajowhite,
324 navy, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen,
325 paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple,
326 red, rosybrown, royalblue, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna,
327 silver, skyblue, slateblue, slategray, slategrey, snow, springgreen, steelblue, tan, teal,
328 thistle, tomato, turquoise, violet, wheat, white, whitesmoke, yellow, yellowgreen
329  
330 or the rgb-hex-notation:
331  
332 #rgb, #rrggbb, #rrrgggbbb and #rrrrggggbbbb
333  
334 or the cmyk-hex-notation:
335  
336 %cmyk, %ccmmyykk, %cccmmmyyykkk and %ccccmmmmyyyykkkk
337  
338 or the hsl-hex-notation:
339  
340 &hsl, &hhssll, &hhhssslll and &hhhhssssllll
341  
342 and additionally the hsv-hex-notation:
343  
344 !hsv, !hhssvv, !hhhsssvvv and !hhhhssssvvvv
345  
346 =cut
347  
348 sub strokecolor {
349 0 ▶ my $self=shift @_;
Subroutine strokecolor: not called CC=1 SCAR=6.9
Pod documented
350 0 $self->{gfx}->strokecolor(@_);
351 0 return($self);
352 }
353  
354 =item $pdf->linedash @dash
355  
356 Sets linedash.
357  
358 =cut
359  
360 sub linedash {
361 0 ▶ my ($self,@a)=@_;
Subroutine linedash: not called CC=1 SCAR=6.9
Pod documented
362 0 $self->{gfx}->linedash(@a);
363 0 return($self);
364 }
365  
366 =item $pdf->linewidth $width
367  
368 Sets linewidth.
369  
370 =cut
371  
372 sub linewidth {
373 0 ▶ my ($self,$linewidth)=@_;
Subroutine linewidth: not called CC=1 SCAR=6.9
Pod documented
374 0 $self->{gfx}->linewidth($linewidth);
375 0 return($self);
376 }
377  
378 =item $pdf->transform %opts
379  
380 Sets transformations (eg. translate, rotate, scale, skew) in pdf-canonical order.
381  
382 B<Example:>
383  
384 $pdf->transform(
385 -translate => [$x,$y],
386 -rotate => $rot,
387 -scale => [$sx,$sy],
388 -skew => [$sa,$sb],
389 )
390  
391 =cut
392  
393 sub transform {
394 0 ▶ my ($self,%opt)=@_;
Subroutine transform: not called CC=1 SCAR=6.9
Pod documented
395 0 $self->{gfx}->transform(%opt);
396 0 return($self);
397 }
398  
399 =item $pdf->move $x, $y
400  
401 =cut
402  
403 sub move { # x,y ...
404 0 ▶ my $self=shift @_;
Subroutine move: not called CC=1 SCAR=6.9
Pod documented
405 0 $self->{gfx}->move(@_);
406 0 return($self);
407 }
408  
409 =item $pdf->line $x, $y
410  
411 =cut
412  
413 sub line { # x,y ...
414 0 ▶ my $self=shift @_;
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
415 0 $self->{gfx}->line(@_);
416 0 return($self);
417 }
418  
419 =item $pdf->curve $x1, $y1, $x2, $y2, $x3, $y3
420  
421 =cut
422  
423 sub curve { # x1,y1,x2,y2,x3,y3 ...
424 0 ▶ my $self=shift @_;
Subroutine curve: not called CC=1 SCAR=6.9
Pod documented
425 0 $self->{gfx}->curve(@_);
426 0 return($self);
427 }
428  
429 =item $pdf->arc $x, $y, $a, $b, $alfa, $beta, $move
430  
431 =cut
432  
433 sub arc { # x,y,a,b,alf,bet[,mov]
434 0 ▶ my $self=shift @_;
Subroutine arc: not called CC=1 SCAR=6.9
Pod documented
435 0 $self->{gfx}->arc(@_);
436 0 return($self);
437 }
438  
439 =item $pdf->ellipse $x, $y, $a, $b
440  
441 =cut
442  
443 sub ellipse {
444 0 ▶ my $self=shift @_;
Subroutine ellipse: not called CC=1 SCAR=6.9
Pod documented
445 0 $self->{gfx}->ellipse(@_);
446 0 return($self);
447 }
448  
449 =item $pdf->circle $x, $y, $r
450  
451 =cut
452  
453 sub circle {
454 0 ▶ my $self=shift @_;
Subroutine circle: not called CC=1 SCAR=6.9
Pod documented
455 0 $self->{gfx}->circle(@_);
456 0 return($self);
457 }
458  
459 =item $pdf->rect $x,$y, $w,$h
460  
461 =cut
462  
463 sub rect { # x,y,w,h ...
464 0 ▶ my $self=shift @_;
Subroutine rect: not called CC=1 SCAR=6.9
Pod documented
465 0 $self->{gfx}->rect(@_);
466 0 return($self);
467 }
468  
469 =item $pdf->rectxy $x1,$y1, $x2,$y2
470  
471 =cut
472  
473 sub rectxy {
474 0 ▶ my $self=shift @_;
Subroutine rectxy: not called CC=1 SCAR=6.9
Pod documented
475 0 $self->{gfx}->rectxy(@_);
476 0 return($self);
477 }
478  
479 =item $pdf->poly $x1,$y1, ..., $xn,$yn
480  
481 =cut
482  
483 sub poly {
484 0 ▶ my $self=shift @_;
Subroutine poly: not called CC=1 SCAR=6.9
Pod documented
485 0 $self->{gfx}->poly(@_);
486 0 return($self);
487 }
488  
489 =item $pdf->close
490  
491 =cut
492  
493 sub close {
494 0 ▶ my $self=shift @_;
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
495 0 $self->{gfx}->close;
496 0 return($self);
497 }
498  
499 =item $pdf->stroke
500  
501 =cut
502  
503 sub stroke {
504 0 ▶ my $self=shift @_;
Subroutine stroke: not called CC=1 SCAR=6.9
Pod documented
505 0 $self->{gfx}->stroke;
506 0 return($self);
507 }
508  
509 =item $pdf->fill
510  
511 =cut
512  
513 sub fill { # nonzero
514 0 ▶ my $self=shift @_;
Subroutine fill: not called CC=1 SCAR=6.9
Pod documented
515 0 $self->{gfx}->fill;
516 0 return($self);
517 }
518  
519 =item $pdf->fillstroke
520  
521 =cut
522  
523 sub fillstroke { # nonzero
524 0 ▶ my $self=shift @_;
Subroutine fillstroke: not called CC=1 SCAR=6.9
Pod documented
525 0 $self->{gfx}->fillstroke;
526 0 return($self);
527 }
528  
529 =item $pdf->image $imgobj, $x,$y, $w,$h
530  
531 =item $pdf->image $imgobj, $x,$y, $scale
532  
533 =item $pdf->image $imgobj, $x,$y
534  
535 B<Please Note:> The width/height or scale given
536 is in user-space coordinates which is subject to
537 transformations which may have been specified beforehand.
538  
539 Per default this has a 72dpi resolution, so if you want an
540 image to have a 150 or 300dpi resolution, you should specify
541 a scale of 72/150 (or 72/300) or adjust width/height accordingly.
542  
543 =cut
544  
545 sub image {
546 0 ▶ my $self=shift @_;
Subroutine image: not called CC=1 SCAR=6.9
Pod documented
547 0 $self->{gfx}->image(@_);
548 0 return($self);
549 }
550  
551 =item $pdf->textstart
552  
553 =cut
554  
555 sub textstart {
556 0 ▶ my $self=shift @_;
Subroutine textstart: not called CC=1 SCAR=6.9
Pod documented
557 0 $self->{gfx}->textstart;
558 0 return($self);
559 }
560  
561 =item $pdf->textfont $fontobj,$size
562  
563 =cut
564  
565 sub textfont {
566 0 ▶ my $self=shift @_;
Subroutine textfont: not called CC=1 SCAR=6.9
Pod documented
567 0 $self->{gfx}->font(@_);
568 0 return($self);
569 }
570  
571 =item $txt->textleading $leading
572  
573 =cut
574  
575 # Deprecated: leading is the correct term for this operator
576 0 ▶sub textlead { return textleading(@_) }
Subroutine textlead: not called CC=1 SCAR=6.9
Pod undocumented
577  
578 sub textleading {
579 0 ▶ my $self=shift @_;
Subroutine textleading: not called CC=1 SCAR=6.9
Pod documented
580 0 $self->{gfx}->leading(@_);
581 0 return($self);
582 }
583  
584 =item $pdf->text $string
585  
586 Applies the given text.
587  
588 =cut
589  
590 sub text {
591 0 ▶ my $self=shift @_;
Subroutine text: not called CC=2 SCAR=17.9
Pod documented
592 0 ▶ return $self->{gfx}->text(@_)||$self;
Condition0%0/3
$self->{'gfx'}->text(@_) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'gfx'}->text(@_) || $self
$self->{'gfx'}->text(@_) $self
Truth table0%0/3
A || B
A= $self->{'gfx'}->text(@_)B= $self
ABresult
1X1
011
000
593 }
594  
595 =item $pdf->nl
596  
597 =cut
598  
599 sub nl {
600 0 ▶ my $self=shift @_;
Subroutine nl: not called CC=1 SCAR=6.9
Pod documented
601 0 $self->{gfx}->nl;
602 0 return($self);
603 }
604  
605 =item $pdf->textend
606  
607 =cut
608  
609 sub textend {
610 0 ▶ my $self=shift @_;
Subroutine textend: not called CC=1 SCAR=6.9
Pod documented
611 0 $self->{gfx}->textend;
612 0 return($self);
613 }
614  
615 =item $pdf->print $font, $size, $x, $y, $rot, $just, $text
616  
617 Convenience wrapper for shortening the textstart..textend sequence.
618  
619 =cut
620  
621 sub print {
622 0 ▶ my $self=shift @_;
Subroutine print: not called CC=3 SCAR=24.8
Pod documented
623 0 my ($font, $size, $x, $y, $rot, $just, @text)=@_;
624 0 my $text=join(' ',@text);
625 0 $self->textstart;
626 0 $self->textfont($font, $size);
627 0 $self->transform(
628 -translate=>[$x, $y],
629 -rotate=> $rot,
630 );
631 0 ▶ if($just==1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($just == 1) { } 0 0 0
elsif ($just == 2) { } 0 0 0
632 0 $self->{gfx}->text_center($text);
633 } elsif($just==2) {
634 0 $self->{gfx}->text_right($text);
635 } else {
636 0 $self->text(@text);
637 }
638 0 $self->textend;
639 0 return($self);
640 }
641  
642 2 1;
643  
644 __END__
« API2/Resource/Glyphs.pm ↑ Summary API2/Resource/UniFont.pm »