line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ICC::Profile::text; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
100216
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
120
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.12; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# revised 2018-08-07 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright © 2004-2020 by William B. Birkett |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# inherit from Shared |
13
|
2
|
|
|
2
|
|
9
|
use parent qw(ICC::Shared); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# create new text tag object |
16
|
|
|
|
|
|
|
# parameters: ([text_string]) |
17
|
|
|
|
|
|
|
# returns: (ref_to_object) |
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# get object class |
21
|
1
|
|
|
1
|
0
|
607
|
my $class = shift(); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# create empty text object |
24
|
1
|
|
|
|
|
3
|
my $self = [ |
25
|
|
|
|
|
|
|
{}, # object header |
26
|
|
|
|
|
|
|
'' # text string |
27
|
|
|
|
|
|
|
]; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# if parameter supplied |
30
|
1
|
50
|
|
|
|
3
|
if (@_) { |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# save it |
33
|
0
|
|
|
|
|
0
|
$self->[1] = shift(); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# bless object |
38
|
1
|
|
|
|
|
3
|
bless($self, $class); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# return object reference |
41
|
1
|
|
|
|
|
1
|
return($self); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# create text tag object from ICC profile |
46
|
|
|
|
|
|
|
# parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
47
|
|
|
|
|
|
|
# returns: (ref_to_object) |
48
|
|
|
|
|
|
|
sub new_fh { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# get object class |
51
|
1
|
|
|
1
|
0
|
492
|
my $class = shift(); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# create empty text object |
54
|
1
|
|
|
|
|
3
|
my $self = [ |
55
|
|
|
|
|
|
|
{}, # object header |
56
|
|
|
|
|
|
|
'' # text string |
57
|
|
|
|
|
|
|
]; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# verify 3 parameters |
60
|
1
|
50
|
|
|
|
4
|
(@_ == 3) or croak('wrong number of parameters'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# read text data from profile |
63
|
1
|
|
|
|
|
3
|
_readICCtext($self, @_); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# bless object |
66
|
1
|
|
|
|
|
2
|
bless($self, $class); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# return object reference |
69
|
1
|
|
|
|
|
7
|
return($self); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# writes text tag object to ICC profile |
74
|
|
|
|
|
|
|
# parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
75
|
|
|
|
|
|
|
sub write_fh { |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# verify 4 parameters |
78
|
1
|
50
|
|
1
|
0
|
873
|
(@_ == 4) or croak('wrong number of parameters'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# write text data to profile |
81
|
1
|
|
|
|
|
4
|
goto &_writeICCtext; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# get tag size (for writing to profile) |
86
|
|
|
|
|
|
|
# returns: (tag_size) |
87
|
|
|
|
|
|
|
sub size { |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# get parameters |
90
|
3
|
|
|
3
|
0
|
373
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# get text string |
93
|
3
|
|
|
|
|
8
|
my $txt = $self->[1]; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# strip out non-ASCII characters |
96
|
3
|
|
|
|
|
11
|
$txt =~ s/[^\x00-\x7F]//g; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# return size (string is null terminated) |
99
|
3
|
|
|
|
|
19
|
return(8 + length($txt) + 1); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# get/set text string |
104
|
|
|
|
|
|
|
# parameters: ([text_string]) |
105
|
|
|
|
|
|
|
# returns: (text_string) |
106
|
|
|
|
|
|
|
sub text { |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# get object reference |
109
|
0
|
|
|
0
|
0
|
0
|
my $self = shift(); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# if parameter supplied |
112
|
0
|
0
|
|
|
|
0
|
if (@_) { |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# save it |
115
|
0
|
|
|
|
|
0
|
$self->[1] = shift(); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# return text string |
120
|
0
|
|
|
|
|
0
|
return($self->[1]); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# print object contents to string |
125
|
|
|
|
|
|
|
# format is an array structure |
126
|
|
|
|
|
|
|
# parameter: ([format]) |
127
|
|
|
|
|
|
|
# returns: (string) |
128
|
|
|
|
|
|
|
sub sdump { |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# get parameters |
131
|
0
|
|
|
0
|
1
|
0
|
my ($self, $p) = @_; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# local variables |
134
|
0
|
|
|
|
|
0
|
my ($s, $fmt); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# resolve parameter to an array reference |
137
|
0
|
0
|
|
|
|
0
|
$p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; |
|
|
0
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# get format string |
140
|
0
|
0
|
0
|
|
|
0
|
$fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# set string to object ID |
143
|
0
|
|
|
|
|
0
|
$s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# return |
146
|
0
|
|
|
|
|
0
|
return($s); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# read text tag from ICC profile |
151
|
|
|
|
|
|
|
# parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
152
|
|
|
|
|
|
|
sub _readICCtext { |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# get parameters |
155
|
1
|
|
|
1
|
|
2
|
my ($self, $parent, $fh, $tag) = @_; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# local variables |
158
|
1
|
|
|
|
|
1
|
my ($buf); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# save tag signature |
161
|
1
|
|
|
|
|
2
|
$self->[0]{'signature'} = $tag->[0]; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# seek start of tag |
164
|
1
|
|
|
|
|
9
|
seek($fh, $tag->[1], 0); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# read tag |
167
|
1
|
|
|
|
|
8
|
read($fh, $buf, $tag->[2]); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# unpack text string (null terminated) |
170
|
1
|
|
|
|
|
5
|
$self->[1] = unpack('x8 Z*', $buf); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# write text tag to ICC profile |
175
|
|
|
|
|
|
|
# parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
176
|
|
|
|
|
|
|
sub _writeICCtext { |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# get parameters |
179
|
1
|
|
|
1
|
|
2
|
my ($self, $parent, $fh, $tag) = @_; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# local variables |
182
|
1
|
|
|
|
|
2
|
my ($txt); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# seek start of tag |
185
|
1
|
|
|
|
|
7
|
seek($fh, $tag->[1], 0); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# get text string |
188
|
1
|
|
|
|
|
3
|
$txt = $self->[1]; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# strip out non-ASCII characters and warn |
191
|
1
|
50
|
|
|
|
6
|
($txt =~ s/[^\x00-\x7F]//g) && carp('non-ASCII character(s) removed from \'text\' tag'); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# write tag |
194
|
1
|
|
|
|
|
16
|
print $fh pack('a4 x4 Z*', 'text', $txt); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |