charset: distinct column count per table
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 6 Apr 2017 19:06:56 +0000 (21:06 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 24 Apr 2017 23:51:42 +0000 (01:51 +0200)
Prevent unicode planes from affecting other tables.

charset.plp

index 73b37407b2ff71ecce5fd84f1d526c8aa823caaa..8dfa91e358405680b2226fac6fa57494bf58d677 100644 (file)
@@ -22,7 +22,6 @@ Html({
 use POSIX qw( ceil );
 use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
-my $cols = 16;  # columns
 
 # generate character table(s)
 # (~16x faster than decoding in loop;
@@ -39,7 +38,7 @@ my %ALIAS = (
 );
 my @request = map {
        if (my $input = $_) {
-               my %row = (offset => 0);
+               my %row = (offset => 0, cols => 16);
                my $endpoint = 255;
                if ($input =~ s/^--//) {
                        $row{offset} = $endpoint > 160 ? 160 : 48;
@@ -67,7 +66,7 @@ my @request = map {
                        $row{set} = 'Unicode planes';
                        $row{cell} = do 'charset-ucplanes.inc.pl'
                                or Alert('Table data could not be read', $@ || $!);
-                       $cols *= 2;
+                       $row{cols} *= 2;
                }
                elsif ($row{set} = Encode::resolve_alias($input)) {
                        if ($row{set} eq 'Internal') {
@@ -107,10 +106,12 @@ for my $cp437 (grep {$request[$_]->{set} eq 'cp437'} 0 .. $#request) {
 }
 
 sub range_cell {
-       my ($table, $offset) = @_;
+       my ($info, $offset) = @_;
+       my $table = $info->{cell} or return;
        my $def = $table->{$offset} or return;
        my ($len, $class, $name, $title) = @{$def};
 
+       my $cols = $info->{cols};
        my $colsize = $table->{colsize} || 1;
        my $attr = '';
        $len /= $colsize;
@@ -157,6 +158,7 @@ sub range_cell {
 }
 
 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
@@ -188,7 +190,7 @@ for my $row (@request) {
                for my $lsb (0 .. $cols - 1) {
                        my $val = ( ($msb * $cols) + $lsb ) * $colsize;
                        if ($row->{cell}) {
-                               print range_cell($row->{cell}, $val);
+                               print range_cell($row, $val);
                                next;
                        }