File Coverage

blib/lib/PDF/Builder/Resource/ColorSpace/Indexed/WebColor.pm
Criterion Covered Total %
statement 51 51 100.0
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 61 63 96.8


line stmt bran cond sub pod time code
1             package PDF::Builder::Resource::ColorSpace::Indexed::WebColor;
2              
3 2     2   1057 use base 'PDF::Builder::Resource::ColorSpace::Indexed';
  2         5  
  2         610  
4              
5 2     2   17 use strict;
  2         4  
  2         42  
6 2     2   10 use warnings;
  2         4  
  2         152  
7             #no warnings qw[ deprecated recursion uninitialized ];
8              
9             our $VERSION = '3.023'; # VERSION
10             our $LAST_UPDATE = '3.021'; # manually update whenever code is changed
11              
12             =head1 NAME
13              
14             PDF::Builder::Resource::ColorSpace::Indexed::WebColor - colorspace support for "Web Safe" Device RGB colors. Inherits from L
15              
16             =cut
17              
18 2     2   14 use PDF::Builder::Basic::PDF::Utils;
  2         5  
  2         200  
19 2     2   14 use PDF::Builder::Util;
  2         4  
  2         281  
20 2     2   16 use Scalar::Util qw(weaken);
  2         4  
  2         994  
21              
22             sub new {
23 1     1 1 3 my ($class, $pdf) = @_;
24              
25 1 50       4 $class = ref $class if ref $class;
26 1         5 my $self = $class->SUPER::new($pdf, pdfkey());
27 1 50       2 $pdf->new_obj($self) unless $self->is_obj($pdf);
28 1         3 $self->{' apipdf'} = $pdf;
29 1         3 weaken $self->{' apipdf'};
30 1         3 my $csd = PDFDict();
31 1         4 $pdf->new_obj($csd);
32 1         3 $csd->{'Filter'} = PDFArray(PDFName('ASCIIHexDecode'));
33 1         3 $csd->{'WhitePoint'} = PDFArray(map {PDFNum($_)} (0.95049, 1, 1.08897));
  3         9  
34 1         3 $csd->{'BlackPoint'} = PDFArray(map {PDFNum($_)} (0, 0, 0));
  3         6  
35 1         2 $csd->{'Gamma'} = PDFArray(map {PDFNum($_)} (2.22218, 2.22218, 2.22218));
  3         5  
36 1         3 $csd->{' stream'}='';
37              
38 1         2 foreach my $r (0,0x33,0x66,0x99,0xCC,0xFF) {
39 6         11 foreach my $g (0,0x33,0x66,0x99,0xCC,0xFF) {
40 36         52 foreach my $b (0,0x33,0x66,0x99,0xCC,0xFF) {
41 216         401 $csd->{' stream'} .= pack('CCC', $r,$g,$b);
42             }
43             }
44             } # 0-215
45              
46 1         3 foreach my $r (0,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF) {
47 16         29 $csd->{' stream'} .= pack('CCC', $r,$r,$r);
48             } # 216-231
49 1         3 foreach my $r (0,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF) {
50 16         71 $csd->{' stream'} .= pack('CCC', map { $_*255 } namecolor('!'.sprintf('%02X', $r).'FFFF'));
  48         135  
51             } # 232-247
52 1         3 foreach my $r (0,0x22,0x44,0x66,0x88,0xAA,0xCC,0xEE) {
53 8         33 $csd->{' stream'} .= pack('CCC', map { $_*255 } namecolor('!'.sprintf('%02X', $r).'FF99'));
  24         69  
54             } # 232-247
55              
56 1         16 $csd->{' stream'} .= "\x00" x 768;
57 1         5 $csd->{' stream'} = substr($csd->{' stream'}, 0, 768);
58              
59 1         6 $self->add_elements(PDFName('DeviceRGB'), PDFNum(255), $csd);
60 1         2 $self->{' csd'} = $csd;
61              
62 1         4 return $self;
63             }
64              
65             1;