charset: coalesce and abbreviate rowspan>3
[sheet.git] / charset.plp
index 6119859478217b3a87f5a467c0619e975de8392c..18d7c50453c83ca2237ee5c9773473123f338a7f 100644 (file)
@@ -85,7 +85,7 @@ sub tabinput {
                use List::Util qw( first pairfirst pairs );
 
                state $INHERIT = {
-                       'cp437'       => ['cp850' => 0], # ascii range overridden later
+                       'cp437'       => ['cp850' => 0, 'ascii' => '0-31+128'], # ascii range overridden later
                        'gsm0338'     => ['ascii' => '0-127'],
 
                        'iso-8859-2'  => ['iso-8859-1' => '160'],
@@ -166,16 +166,21 @@ sub tabinput {
                }
                elsif (defined $visible->{ascii}) {
                        $row{parent} = $parents[0];
-                       $params = $parents[1] || 128;
+                       $params = $parents[1] // 128;
                        $params = 128 if $params >= 128;  # ascii offset at most
                }
                elsif (@parents) {
                        $row{parent} = $parents[0];
+                       $params = $parents[1] if $parents[1] == 0;  # apply ascii end
                }
-               $visible->{$_} //= 0 for $row{parent};
+               $visible->{$_} //= 0 for $row{parent} || ();
+       }
+       else {
+               # manual option to double table width
+               $row{cols} *= 2 if $params =~ s/[+]\z//;
        }
 
-       if (defined $params) {
+       if (length $params) {
                $params =~ m{
                        \A (?<offset> \d+)
                        (?: (?: [-] (?<stop> \d+) )? (?: [+] (?<restart> \d+) ) )?
@@ -298,11 +303,22 @@ sub range_cell {
        }
        elsif (my $rows = int($len / $cols)) {
                # multiple full rows
+               my $rowsize = $colsize * $cols;
                if ($len -= $rows * $cols) {
                        # partial row remains
-                       $table->{$offset + $colsize*$rows * $cols} //= [$len*$colsize, "$class joinu", '', $title];
+                       $table->{$offset + $rowsize * $rows} //= [$len*$colsize, "$class joinu", '', $title];
                        $class .= ' joind';
                }
+
+               # coalesce multiple rows
+               while ($rows > 3) {
+                       $info->{skip}->{$offset += $rowsize}++;
+                       $rows--;
+               }
+               if ($rows > 2) {
+                       $info->{skip}->{$offset += $rowsize} = 0;
+               }
+
                $attr .= sprintf ' rowspan=%d', $rows;
                $len = $cols;
        }
@@ -341,7 +357,10 @@ for my $row (@request) {
                }
 
                print '<tr><th>';
-               {
+               if (defined $row->{skip}->{$offset}) {
+                       print '⋮';
+               }
+               else {
                        if (my $rowmod = $offset % $rowdiv) {
                                # offset in column units
                                printf '<small>+%X</small>', $rowmod;