X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/b37bf3bbd6062843787fe47987eb19bdc546e9e2..bf64871d2554e77756e10b896bb63589d15b4f73:/charset.plp diff --git a/charset.plp b/charset.plp index db178d9..b1c680e 100644 --- a/charset.plp +++ b/charset.plp @@ -15,6 +15,8 @@ Html({ data => [qw'charset-unicode.inc.pl charset-utf8.inc.pl'], }); +my @tablist = split m{/+}, $Request || 'default'; + :>
$paramsis not in format start(-stop)(+restart(-end))", + ]); + + $row{offset} = $+{offset}; + $endpoint = $+{endpoint} if $+{endpoint}; + if (my $restart = $+{restart}) { + my $skip = int(($+{stop} || $row{offset}) / $row{cols}); + for ($skip + 1 .. ($restart / $row{cols}) - 1) { + $row{skip}->{ $_ * $row{cols} - $row{offset} }++; + } } + } - if ($input =~ /^U([0-9a-f]+)(?:-([0-9a-f]+))?/) { - my $start = hex($1) << ($2 ? 4 : 8); - my $end = $2 ? hex($2) << 4 : $start + 240; - $row{table} = join '', map { chr } $start .. $end+15; - utf8::upgrade($row{table}); # prevent latin1 output - $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8; + if ($input =~ /^U([0-9a-fA-F]+)(?:-([0-9a-fA-F]+))?/) { + my $start = hex($1) << ($2 ? 4 : 8); + my $end = $2 ? (hex($2) << 4) + $row{cols} - 1 : $start + 255; + $row{table} = join '', map { chr } $start .. $end; + utf8::upgrade($row{table}); # prevent latin1 output + $row{endpoint} = $end - $start; + $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8; + $row{offset} = $start % 256; + } + elsif ($input eq 'U') { + $row{set} = 'Unicode planes'; + $row{cell} = do 'charset-ucplanes.inc.pl' + or Alert('Table data could not be read', $@ || $!); + $row{cols} *= 2; + $row{endpoint} = 1023 * $row{cell}->{colsize}; + } + elsif ($row{set} = Encode::resolve_alias($input)) { + if ($row{set} eq 'Internal') { + $row{set} = 'Unicode BMP'; + $row{cell} = do 'charset-unicode.inc.pl' + or Alert('Table data could not be read', $@ || $!); + $row{endpoint} = ($endpoint || 8191) * $row{cell}->{colsize}; } - elsif ($input eq 'U') { - $row{table} = ' ' x 1024; - $row{set} = 'Unicode planes'; - $row{cell} = do 'charset-ucplanes.inc.pl' + elsif ($row{set} eq 'utf-8-strict') { + $row{set} = 'UTF-8'; + $row{cell} = do 'charset-utf8.inc.pl' or Alert('Table data could not be read', $@ || $!); - $row{cols} *= 2; + $row{endpoint} = 255; } - elsif ($row{set} = Encode::resolve_alias($input)) { - if ($row{set} eq 'Internal') { - $row{table} = ' ' x ($endpoint < 255 ? 640 : 8192); - $row{set} = 'Unicode BMP'; - $row{cell} = do 'charset-unicode.inc.pl' - or Alert('Table data could not be read', $@ || $!); - } - elsif ($row{set} eq 'utf-8-strict') { - $row{table} = undef; - $row{set} = 'UTF-8'; - $row{cell} = do 'charset-utf8.inc.pl' - or Alert('Table data could not be read', $@ || $!); + else { + if ($row{set} eq 'MacHebrew' or $row{set} eq 'MacThai') { + # array of possibly multiple characters per code point + $row{table} = [ + map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $endpoint + ]; } else { + # ~16x faster than decoding in loop; + # substr strings is twice as fast as splitting to an array $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $endpoint); } + $row{endpoint} = $endpoint - $row{offset}; + + if ($row{set} eq 'cp437' and !$row{offset}) { + substr($row{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign + substr($row{table}, 0, 32) = pack 'U*', map {hex} qw( + 2007 263A 263B 2665 2666 2663 2660 2022 + 25D8 25CB 25D9 2642 2640 266A 266B 263C + 25BA 25C4 2195 203C 00B6 00A7 25AC 21A8 + 2191 2193 2192 2190 221F 2194 25B2 25BC + ); + } + + $visible->{ascii} = # assume common base + $visible->{ $row{set} } = 1; } - else { - Alert("Encoding
$inputunknown"); - } - $row{set} ? \%row : (); } else { - (); + Alert("Encoding
$inputunknown"); + return; } -} map { defined $ALIAS{$_} ? @{ $ALIAS{$_} } : $_ } - $Request =~ /\w/ ? split(m{[/+\s]}, $Request) : 'default'; -my $NOCHAR = chr 0xFFFD; - -for my $cp437 (grep {$request[$_]->{set} eq 'cp437'} 0 .. $#request) { - substr($request[$cp437]->{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign - substr($request[$cp437]->{table}, 0, 32) = pack 'U*', map {hex} qw( - 2007 263A 263B 2665 2666 2663 2660 2022 25D8 25CB 25D9 2642 2640 266A 266B 263C - 25BA 25C4 2195 203C 00B6 00A7 25AC 21A8 2191 2193 2192 2190 221F 2194 25B2 25BC - ); + push @request, \%row; } +tabinput($_) for @tablist; + +my $NOCHAR = chr 0xFFFD; sub range_cell { my ($info, $offset) = @_; @@ -161,22 +323,28 @@ for my $row (@request) { my $cols = $row->{cols}; my $colsize = $row->{cell} && $row->{cell}->{colsize} || 1; my $coldigits = ceil(log($colsize * $cols) / log(16)); # uniform length of hexadecimal header - my $rowdiv = 16 ** $coldigits; # divider of row headers + my $rowdiv = 16 ** $coldigits; # row divide for column digits + $rowdiv = 1 if $rowdiv != $cols * $colsize; # divide only if all columns are matched my $offset = 0; - my $endpoint = $offset + (length($row->{table}) || 256) * $colsize; printf '
â±"; + print "<$section> | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
", $rowdiv == 1 ? '+' : 'â±'; printf ' | %0*X', $coldigits, $_ * $colsize for 0 .. $cols - 1; print "\n"; } print ' | ||||||||||||
'; { if (my $rowmod = $offset % $rowdiv) { @@ -194,12 +362,27 @@ for my $row (@request) { next; } - my $glyph = substr $row->{table}, $offset, 1; + my $glyph = ref $row->{table} eq 'ARRAY' ? $row->{table}->[$offset] : + substr $row->{table}, $offset, 1; if ($glyph eq $NOCHAR) { print ' | '; next; } + if (exists $get{compare}) { + state $visible = {}; + my $cp = $offset + $row->{offset}; + printf ' | %2$s',
+ $cp == ord $glyph ? 'l4' :
+ $row->{parent} && $glyph eq
+ Encode::decode($row->{parent}, pack 'C', $cp) ? 'l3' :
+ $visible->{$glyph} ? 'l2' :
+ 'l1',
+ $glyphs->glyph_html($glyph);
+ $visible->{$glyph}++;
+ next;
+ }
+
print "\n".$glyphs->glyph_cell($glyph);
}
continue {
@@ -214,7 +397,13 @@ for my $row (@request) {
-
|