| 1 | package PDF::API2::Resource::ColorSpace::Separation; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use base 'PDF::API2::Resource::ColorSpace'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '2.044'; # VERSION | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use PDF::API2::Basic::PDF::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use PDF::API2::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | PDF::API2::Resource::ColorSpace::Separation - Support for color space separations | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =over | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =item $cs = PDF::API2::Resource::ColorSpace::Separation->new $pdf, $key, %parameters | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Returns a new colorspace object. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub new { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my ($class, $pdf, $key, $name, @clr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = $class->SUPER::new($pdf, $key); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | $pdf->new_obj($self) unless $self->is_obj($pdf); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $self->{' apipdf'} = $pdf; | |||||||||||||||||||||||||||
| 35 | 0 | weaken $self->{' apipdf'}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $fct = PDFDict(); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $csname; | |||||||||||||||||||||||||||
| 40 | 0 | $clr[0] = lc($clr[0]); | |||||||||||||||||||||||||||
| 41 | 0 | $self->color(@clr); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($clr[0] =~ /^[a-z\#\!]+/) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 43 | # colorname or #! specifier | ||||||||||||||||||||||||||||
| 44 | # with rgb target colorspace | ||||||||||||||||||||||||||||
| 45 | # namecolor returns always a RGB | ||||||||||||||||||||||||||||
| 46 | 0 | my ($r, $g, $b) = namecolor($clr[0]); | |||||||||||||||||||||||||||
| 47 | 0 | $csname = 'DeviceRGB'; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | $fct->{'FunctionType'} = PDFNum(0); | |||||||||||||||||||||||||||
| 50 | 0 | $fct->{'Size'} = PDFArray(PDFNum(2)); | |||||||||||||||||||||||||||
| 51 | 0 | $fct->{'Range'} = PDFArray(map { PDFNum($_) } ($r, 1, $g, 1, $b, 1)); | |||||||||||||||||||||||||||
| 52 | 0 | $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1)); | |||||||||||||||||||||||||||
| 53 | 0 | $fct->{'BitsPerSample'} = PDFNum(8); | |||||||||||||||||||||||||||
| 54 | 0 | $fct->{' stream'} = "\xff\xff\xff\x00\x00\x00"; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | elsif ($clr[0] =~ /^[\%]+/) { | ||||||||||||||||||||||||||||
| 57 | # % specifier | ||||||||||||||||||||||||||||
| 58 | # with cmyk target colorspace | ||||||||||||||||||||||||||||
| 59 | 0 | my ($c, $m, $y, $k) = namecolor_cmyk($clr[0]); | |||||||||||||||||||||||||||
| 60 | 0 | $csname = 'DeviceCMYK'; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $fct->{'FunctionType'} = PDFNum(0); | |||||||||||||||||||||||||||
| 63 | 0 | $fct->{'Size'} = PDFArray(PDFNum(2)); | |||||||||||||||||||||||||||
| 64 | 0 | $fct->{'Range'} = PDFArray(map { PDFNum($_) } (0, $c, 0, $m, 0, $y, 0, $k)); | |||||||||||||||||||||||||||
| 65 | 0 | $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1)); | |||||||||||||||||||||||||||
| 66 | 0 | $fct->{'BitsPerSample'} = PDFNum(8); | |||||||||||||||||||||||||||
| 67 | 0 | $fct->{' stream'} = "\x00\x00\x00\x00\xff\xff\xff\xff"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | elsif (@clr == 1) { | ||||||||||||||||||||||||||||
| 70 | # grey color spec. | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $clr[0] /= 255 while $clr[0] > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # adjusted for 8/16/32bit spec. | ||||||||||||||||||||||||||||
| 74 | 0 | my $g = $clr[0]; | |||||||||||||||||||||||||||
| 75 | 0 | $csname = 'DeviceGray'; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $fct->{'FunctionType'} = PDFNum(0); | |||||||||||||||||||||||||||
| 78 | 0 | $fct->{'Size'} = PDFArray(PDFNum(2)); | |||||||||||||||||||||||||||
| 79 | 0 | $fct->{'Range'} = PDFArray(PDFNum(0), PDFNum($g)); | |||||||||||||||||||||||||||
| 80 | 0 | $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1)); | |||||||||||||||||||||||||||
| 81 | 0 | $fct->{'BitsPerSample'} = PDFNum(8); | |||||||||||||||||||||||||||
| 82 | 0 | $fct->{' stream'} = "\xff\x00"; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | elsif (@clr == 3) { | ||||||||||||||||||||||||||||
| 85 | # legacy rgb color-spec (0 <= x <= 1) | ||||||||||||||||||||||||||||
| 86 | 0 | my ($r, $g, $b) = @clr; | |||||||||||||||||||||||||||
| 87 | 0 | $csname = 'DeviceRGB'; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $fct->{'FunctionType'} = PDFNum(0); | |||||||||||||||||||||||||||
| 90 | 0 | $fct->{'Size'} = PDFArray(PDFNum(2)); | |||||||||||||||||||||||||||
| 91 | 0 | $fct->{'Range'} = PDFArray(map { PDFNum($_) } ($r, 1, $g, 1, $b, 1)); | |||||||||||||||||||||||||||
| 92 | 0 | $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1)); | |||||||||||||||||||||||||||
| 93 | 0 | $fct->{'BitsPerSample'} = PDFNum(8); | |||||||||||||||||||||||||||
| 94 | 0 | $fct->{' stream'} = "\xff\xff\xff\x00\x00\x00"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | elsif (@clr == 4) { | ||||||||||||||||||||||||||||
| 97 | # legacy cmyk color-spec (0 <= x <= 1) | ||||||||||||||||||||||||||||
| 98 | 0 | my ($c, $m, $y, $k) = @clr; | |||||||||||||||||||||||||||
| 99 | 0 | $csname='DeviceCMYK'; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | $fct->{'FunctionType'} = PDFNum(0); | |||||||||||||||||||||||||||
| 102 | 0 | $fct->{'Size'} = PDFArray(PDFNum(2)); | |||||||||||||||||||||||||||
| 103 | 0 | $fct->{'Range'} = PDFArray(map { PDFNum($_) } (0, $c, 0, $m, 0, $y, 0, $k)); | |||||||||||||||||||||||||||
| 104 | 0 | $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1)); | |||||||||||||||||||||||||||
| 105 | 0 | $fct->{'BitsPerSample'} = PDFNum(8); | |||||||||||||||||||||||||||
| 106 | 0 | $fct->{' stream'} = "\x00\x00\x00\x00\xff\xff\xff\xff"; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | 0 | die 'invalid color specification.'; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | $self->type($csname); | |||||||||||||||||||||||||||
| 112 | 0 | $pdf->new_obj($fct); | |||||||||||||||||||||||||||
| 113 | 0 | $self->add_elements(PDFName('Separation'), | |||||||||||||||||||||||||||
| 114 | PDFName($name), | ||||||||||||||||||||||||||||
| 115 | PDFName($csname), | ||||||||||||||||||||||||||||
| 116 | $fct); | ||||||||||||||||||||||||||||
| 117 | 0 | $self->tintname($name); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | return $self; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =item @color = $res->color | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Returns the base-color of the Separation-Colorspace. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub color { | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
color: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if (@_ and defined $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and defined $_[0]
MC/DC0%0/2
@_ and defined $_[0]
@_
defined $_[0]
Truth table0%0/3
A and B
A= @_B= defined $_[0]
| |||||||||||||||||||||||||||||
| 131 | 0 | $self->{' color'} = [@_]; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | return @{$self->{' color'}}; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item $tintname = $res->tintname $tintname | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Returns the tint-name of the Separation-Colorspace. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub tintname { | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
tintname: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (@_ and defined $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and defined $_[0]
MC/DC0%0/2
@_ and defined $_[0]
@_
defined $_[0]
Truth table0%0/3
A and B
A= @_B= defined $_[0]
| |||||||||||||||||||||||||||||
| 145 | 0 | $self->{' tintname'} = [@_]; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 0 | return @{$self->{' tintname'}}; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | sub param { | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 0 | return $_[0]; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =back | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | 1; | |||||||||||||||||||||||||||