charset: unmultiplied unicode ranges
[sheet.git] / charset.plp
index ff5419f9d904f0f127bda044dbde01305fc9e25a..118658569014cd082cc4f2e532678d6052f78867 100644 (file)
@@ -19,10 +19,10 @@ Html({
 <h1>Character encoding</h1>
 
 <:
+use POSIX qw( ceil );
 use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
 my $cols = 16;  # columns
-my $colsize = 1;  # increment per column
 
 # generate character table(s)
 # (~16x faster than decoding in loop;
@@ -67,7 +67,7 @@ my @request = map {
                        $row{set} = 'Unicode planes';
                        $row{cell} = do 'charset-ucplanes.inc.pl'
                                or Alert('Table data could not be read', $@ || $!);
-                       $colsize = 8;
+                       $cols *= 2;
                }
                elsif ($row{set} = Encode::resolve_alias($input)) {
                        if ($row{set} eq 'Internal') {
@@ -111,6 +111,7 @@ sub range_cell {
        my $def = $table->{$offset} or return;
        my ($len, $class, $name, $title) = @{$def};
 
+       my $colsize = $table->{colsize} || 1;
        my $attr = '';
        $len /= $colsize;
        $name //= $len <= 2 ? 'res' : 'reserved';
@@ -156,12 +157,13 @@ sub range_cell {
 }
 
 for my $row (@request) {
+       my $colsize = $row->{cell} && $row->{cell}->{colsize} || 1;
        printf '<div class="section"><table class="glyphs%s">', !$row->{cell} && ' charmap';
        my $title = $row->{set};
        $title .= " <aside>($_)</aside>" for $row->{setnote} // ();
        printf '<caption>%s</caption>', $title;
        print '<col>' x ($cols + 1);
-       my $coldigits = $colsize * $cols <= 16 ? 1 : 2;  # uniform length of hexadecimal header
+       my $coldigits = ceil(log($colsize * $cols) / log(16));  # uniform length of hexadecimal header
        for my $section (qw{thead}) {
                print "<$section><tr><th>↱";
                printf '<th>%0*X', $coldigits, $_ * $colsize for 0 .. $cols - 1;