| 1 | package ICC::Profile::mluc; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.12; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # revised 2018-08-07 | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Copyright © 2004-2018 by William B. Birkett | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # add development directory | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # inherit from Shared | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent qw(ICC::Shared); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # support modules | ||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Encode; # Unicode module | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # create new mluc tag object | ||||||||||||||||||||||||||||
| 22 | # use 'text' method to add additional entries | ||||||||||||||||||||||||||||
| 23 | # parameters: () | ||||||||||||||||||||||||||||
| 24 | # parameters: (language_code, country_code, text) | ||||||||||||||||||||||||||||
| 25 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 26 | sub new { | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # get object class | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=19.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # create empty mluc object | ||||||||||||||||||||||||||||
| 32 | 1 | my $self = [ | |||||||||||||||||||||||||||
| 33 | {}, # object header | ||||||||||||||||||||||||||||
| 34 | 12, # name record size | ||||||||||||||||||||||||||||
| 35 | [] # array of name records | ||||||||||||||||||||||||||||
| 36 | ]; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # if three parameters | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if (@_ == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # verify country and language codes | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | (length($_[0]) == 2 && length($_[1]) == 2) or croak('country or language code wrong length'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $_[0] == 2 and length $_[1] == 2
MC/DC0%0/2
length $_[0] == 2 and length $_[1] == 2
length $_[0] == 2
length $_[1] == 2
Truth table0%0/3
A and B
A= length $_[0] == 2B= length $_[1] == 2
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # add name record | ||||||||||||||||||||||||||||
| 45 | 0 | $self->[2][0] = [$_[0], $_[1], 0, 0, $_[2]]; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # bless object | ||||||||||||||||||||||||||||
| 50 | 1 | bless($self, $class); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # return object reference | ||||||||||||||||||||||||||||
| 53 | 1 | return($self); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # create mluc tag object from ICC profile | ||||||||||||||||||||||||||||
| 58 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 59 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 60 | sub new_fh { | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # get object class | ||||||||||||||||||||||||||||
| 63 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new_fh: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # create empty mluc object | ||||||||||||||||||||||||||||
| 66 | 1 | my $self = [ | |||||||||||||||||||||||||||
| 67 | {}, # object header | ||||||||||||||||||||||||||||
| 68 | 0, # name record size | ||||||||||||||||||||||||||||
| 69 | [] # array of name records | ||||||||||||||||||||||||||||
| 70 | ]; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 73 | 1 | ▶ | (@_ == 3) or croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # read mluc data from profile | ||||||||||||||||||||||||||||
| 76 | 1 | _readICCmluc($self, @_); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # bless object | ||||||||||||||||||||||||||||
| 79 | 1 | bless($self, $class); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # return object reference | ||||||||||||||||||||||||||||
| 82 | 1 | return($self); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # writes mluc tag object to ICC profile | ||||||||||||||||||||||||||||
| 87 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 88 | sub write_fh { | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # verify 4 parameters | ||||||||||||||||||||||||||||
| 91 | 1 | ▶ | (@_ == 4) or croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Subroutine
write_fh: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # write mluc data to profile | ||||||||||||||||||||||||||||
| 94 | 1 | goto &_writeICCmluc; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # get tag size (for writing to profile) | ||||||||||||||||||||||||||||
| 99 | # returns: (tag_size) | ||||||||||||||||||||||||||||
| 100 | sub size { | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # get parameters | ||||||||||||||||||||||||||||
| 103 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # local variables | ||||||||||||||||||||||||||||
| 106 | 3 | my ($text); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # if count > 0 | ||||||||||||||||||||||||||||
| 109 | 3 | ▶ | if (@{$self->[2]}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # initialize text size | ||||||||||||||||||||||||||||
| 112 | 3 | $text = 0; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # for each name record | ||||||||||||||||||||||||||||
| 115 | 3 | for my $rec (@{$self->[2]}) { | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # add text string size | ||||||||||||||||||||||||||||
| 118 | 3 | $text += length($rec->[4]); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # return size (after Unicode encoding) | ||||||||||||||||||||||||||||
| 123 | 3 | return(16 + @{$self->[2]} * 12 + $text * 2); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # return size | ||||||||||||||||||||||||||||
| 128 | 0 | return(12); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # get/set Unicode mluc string | ||||||||||||||||||||||||||||
| 135 | # updates text if language/country found | ||||||||||||||||||||||||||||
| 136 | # otherwise, adds new table entry | ||||||||||||||||||||||||||||
| 137 | # parameters: (language_code, country_code, [text]) | ||||||||||||||||||||||||||||
| 138 | # returns: (mluc_string) | ||||||||||||||||||||||||||||
| 139 | sub text { | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # get parameters | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
text: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # local variables | ||||||||||||||||||||||||||||
| 145 | 0 | my (@match); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # if two parameters (get) | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # return if name record count = 0 | ||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return if (@{$self->[2]} == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # match country and language codes | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | @match = grep {$_->[1] eq $_[1] && $_->[0] eq $_[0]} @{$self->[2]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # match country code | ||||||||||||||||||||||||||||
| 157 | 0 | ▶ | @match = grep {$_->[1] eq $_[1]} @{$self->[2]} if (@match == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # match language code | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | @match = grep {$_->[0] eq $_[0]} @{$self->[2]} if (@match == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # use first name record | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | @match = ($self->[2][0]) if (@match == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # return name record string | ||||||||||||||||||||||||||||
| 166 | 0 | return($match[0][4]); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # if three parameters (set) | ||||||||||||||||||||||||||||
| 169 | } elsif (@_ == 3) { | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # match country and language codes | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | @match = grep {($_->[1] eq $_[1]) && ($_->[0] eq $_[0])} @{$self->[2]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # if match found | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if (@match) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # set name record text | ||||||||||||||||||||||||||||
| 178 | 0 | $match[0][4] = $_[2]; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # verify country and language codes | ||||||||||||||||||||||||||||
| 183 | 0 | ▶ | (length($_[0]) == 2 && length($_[1]) == 2) or croak('country or language code wrong length'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $_[0] == 2 and length $_[1] == 2
MC/DC0%0/2
length $_[0] == 2 and length $_[1] == 2
length $_[0] == 2
length $_[1] == 2
Truth table0%0/3
A and B
A= length $_[0] == 2B= length $_[1] == 2
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # add new name record | ||||||||||||||||||||||||||||
| 186 | 0 | push(@{$self->[2]}, [$_[0], $_[1], 0, 0, $_[2]]); | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # return name record string | ||||||||||||||||||||||||||||
| 191 | 0 | return($_[2]); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | } else { | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # warning message | ||||||||||||||||||||||||||||
| 196 | 0 | carp('wrong number of parameters'); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | # print object contents to string | ||||||||||||||||||||||||||||
| 203 | # format is an array structure | ||||||||||||||||||||||||||||
| 204 | # parameter: ([format]) | ||||||||||||||||||||||||||||
| 205 | # returns: (string) | ||||||||||||||||||||||||||||
| 206 | sub sdump { | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # get parameters | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # local variables | ||||||||||||||||||||||||||||
| 212 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # get format string | ||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $p->[0] and not ref $p->[0]
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0]
not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # set string to object ID | ||||||||||||||||||||||||||||
| 221 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # return | ||||||||||||||||||||||||||||
| 224 | 0 | return($s); | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # read mluc tag from ICC profile | ||||||||||||||||||||||||||||
| 229 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 230 | sub _readICCmluc { | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | # get parameters | ||||||||||||||||||||||||||||
| 233 | 1 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_readICCmluc: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # local variables | ||||||||||||||||||||||||||||
| 236 | 1 | my ($buf, $cnt); | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # save tag signature | ||||||||||||||||||||||||||||
| 239 | 1 | $self->[0]{'signature'} = $tag->[0]; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # seek start of tag | ||||||||||||||||||||||||||||
| 242 | 1 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # read type sig and count | ||||||||||||||||||||||||||||
| 245 | 1 | read($fh, $buf, 12); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | # unpack name record count | ||||||||||||||||||||||||||||
| 248 | 1 | $cnt = unpack('x8 N', $buf); | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # return if count = 0 | ||||||||||||||||||||||||||||
| 251 | 1 | ▶ | return if ($cnt == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | # read name record size | ||||||||||||||||||||||||||||
| 254 | 1 | read($fh, $buf, 4); | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # unpack name record size | ||||||||||||||||||||||||||||
| 257 | 1 | $self->[1] = unpack('N', $buf); | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # for each name record | ||||||||||||||||||||||||||||
| 260 | 1 | for my $i (0 .. $cnt - 1) { | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | # read name record | ||||||||||||||||||||||||||||
| 263 | 1 | read($fh, $buf, $self->[1]); | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | # unpack language/country codes, length and offset | ||||||||||||||||||||||||||||
| 266 | 1 | $self->[2][$i] = [unpack('a2 a2 N N', $buf)]; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # for each name record | ||||||||||||||||||||||||||||
| 271 | 1 | for my $rec (@{$self->[2]}) { | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | # seek text string | ||||||||||||||||||||||||||||
| 274 | 1 | seek($fh, $tag->[1] + $rec->[3], 0); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | # read text string | ||||||||||||||||||||||||||||
| 277 | 1 | read($fh, $buf, $rec->[2]); | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | # save decoded Unicode data | ||||||||||||||||||||||||||||
| 280 | 1 | $rec->[4] = decode('UTF-16BE', $buf); | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | # write mluc tag to ICC profile | ||||||||||||||||||||||||||||
| 287 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 288 | sub _writeICCmluc { | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # get parameters | ||||||||||||||||||||||||||||
| 291 | 1 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_writeICCmluc: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # local variables | ||||||||||||||||||||||||||||
| 294 | 1 | my ($cnt, $offset); | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # get name record count | ||||||||||||||||||||||||||||
| 297 | 1 | $cnt = @{$self->[2]}; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | # seek start of tag | ||||||||||||||||||||||||||||
| 300 | 1 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # write type sig and count | ||||||||||||||||||||||||||||
| 303 | 1 | print $fh pack('a4 x4 N', 'mluc', $cnt); | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | # return if count = 0 | ||||||||||||||||||||||||||||
| 306 | 1 | ▶ | return if ($cnt == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | # write name record size | ||||||||||||||||||||||||||||
| 309 | 1 | print $fh pack('N', $self->[1]); | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | # compute initial text string offset | ||||||||||||||||||||||||||||
| 312 | 1 | $offset = 16 + $cnt * 12; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | # for each name record | ||||||||||||||||||||||||||||
| 315 | 1 | for my $rec (@{$self->[2]}) { | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | # write language/country codes, length and offset | ||||||||||||||||||||||||||||
| 318 | 1 | print $fh pack('a2 a2 N N', @{$rec}[0 .. 1], length($rec->[4]) * 2, $offset); | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # update offset | ||||||||||||||||||||||||||||
| 321 | 1 | $offset += length($rec->[4]) * 2; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | # for each name record | ||||||||||||||||||||||||||||
| 326 | 1 | for my $rec (@{$self->[2]}) { | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | # write the Unicode string | ||||||||||||||||||||||||||||
| 329 | 1 | print $fh encode('UTF-16BE', $rec->[4]); | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 2 | 1; | |||||||||||||||||||||||||||