Debian Codegraph @

t/Reuse.t

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7 use Test::Deep;
8
9 BEGIN {
10 use_ok('PDF::Reuse') or BAIL_OUT "Can't load PDF::Reuse";
11 }
12
13 ### NOTE: Any changes in the module code which result in a change to the contents of test.pdf
14 ### will require a corresponding change in the expected contents as listed below the __DATA__
15 ### tag at the end of this test file.
16
17 my $built_in_fonts = {
18 'TR' => 'Times-Roman',
19 'TB' => 'Times-Bold',
20 'TI' => 'Times-Italic',
21 'TBI' => 'Times-BoldItalic',
22 'C' => 'Courier',
23 'CB' => 'Courier-Bold',
24 'CO' => 'Courier-Oblique',
25 'CBO' => 'Courier-BoldOblique',
26 'H' => 'Helvetica',
27 'HB' => 'Helvetica-Bold',
28 'HO' => 'Helvetica-Oblique',
29 'HBO' => 'Helvetica-BoldOblique',
30 'S' => 'Symbol',
31 'Z' => 'ZapfDingbats',
32 };
33
34 prFile('./test.pdf');
35
36 my $f_flag = 1 if -e './test.pdf';
37 is ($f_flag, 1, "PDF file created successfully");
38
39 # Test findFont
40 $PDF::Reuse::font = 'H';
41 my ($foINTNAME, $foEXTNAME, $foREFOBJ) = PDF::Reuse::findFont();
42 subtest 'PDF::Reuse::findFont successfully locates fonts' => sub{
43 plan tests => 3;
44 is ($foINTNAME, 'Ft1', "Internal font name is correct");
45 is ($foEXTNAME, 'Helvetica', "External font name is correct");
46 is ($foREFOBJ, '4', "PDF reference object for this font is correct");
47 };
48
49 # Test prText
50 prText(250, 650, 'Hello World !');
51 is ($PDF::Reuse::stream, '0 0 0 rg
52 0 g
53 f
54
55 BT /Ft1 12 Tf 250 650 Td (Hello World !) Tj ET
56 ', "PDF Stream is created correctly");
57
58 # Test prFont
59 is (prFont("Times-Roman"),'Ft2', 'prFont returns the correct internal font name');
60
61
62
63 prEnd();
64
65 # Test newly created PDF file
66 open (my $pdf, "<", "test.pdf") or BAIL_OUT "Can't open test.pdf: $!";
67 binmode $pdf;
68 my @pdf_got = <$pdf>;
69 close $pdf;
70
71 binmode main::DATA, ':encoding(UTF-8)';
72 my @pdf_expected = <main::DATA>;
73 # Line 29 contains two MD% hashes which are time-based and change with every new
74 # PDF file created, so we will ignore it while testing the resulting file.
75 $pdf_expected[31] = ignore();
76 close main::DATA;
77
78 cmp_deeply(\@pdf_got, \@pdf_expected, "PDF file successfully written");
79
80 __DATA__
81 %PDF-1.4
82 %âãÏÓ
83 4 0 obj<</Type/Font/Subtype/Type1/BaseFont/Helvetica/Encoding/WinAnsiEncoding>>endobj
84 5 0 obj<</Type/Font/Subtype/Type1/BaseFont/Times-Roman/Encoding/WinAnsiEncoding>>endobj
85 6 0 obj<</ProcSet[/PDF/Text]/Font << /Ft1 4 0 R/Ft2 5 0 R >>>>endobj
86 7 0 obj<</Length 64>>stream
87 0 0 0 rg
88 0 g
89 f
90
91 BT /Ft1 12 Tf 250 650 Td (Hello World !) Tj ET
92
93 endstream
94 endobj
95 3 0 obj<</Type/Page/Parent 2 0 R/Contents 7 0 R/MediaBox [0 0 595 842]/Resources 6 0 R>>endobj
96 2 0 obj<</Type/Pages/Kids [3 0 R ]/Count 1 >>endobj
97 1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
98 xref
99 0 8
100 0000000000 65535 f
101 0000000515 00000 n
102 0000000463 00000 n
103 0000000368 00000 n
104 0000000015 00000 n
105 0000000101 00000 n
106 0000000189 00000 n
107 0000000258 00000 n
108 trailer
109 <<
110 /Size 8
111 /Root 1 0 R
112 /ID [<d29e8d34f9ec01330a2b6e4e8a6640f7><d29e8d34f9ec01330a2b6e4e8a6640f7>]
113 >>
114 startxref
115 558
116 %%EOF