X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/780c810a9f1cb1461d8c28da4b7ebbb5a34af041..1b025f386b84705e81bd75c166bf0f08d5891608:/charset.plp diff --git a/charset.plp b/charset.plp index ff5419f..28c21c9 100644 --- a/charset.plp +++ b/charset.plp @@ -19,10 +19,9 @@ Html({

Character encoding

<: +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; @@ -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', $@ || $!); - $colsize = 8; + $row{cols} *= 2; } elsif ($row{set} = Encode::resolve_alias($input)) { if ($row{set} eq 'Internal') { @@ -107,10 +106,13 @@ 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; $name //= $len <= 2 ? 'res' : 'reserved'; @@ -156,28 +158,44 @@ 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; # 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 '
', !$row->{cell} && ' charmap'; my $title = $row->{set}; $title .= " " for $row->{setnote} // (); printf '', $title; print '' x ($cols + 1); - my $coldigits = $colsize * $cols <= 16 ? 1 : 2; # uniform length of hexadecimal header for my $section (qw{thead}) { - print "<$section>'; - for my $msb (0 .. ((length($row->{table}) || 256) - 1) / $cols) { - printf '
%s
↱"; + print "<$section>
", $rowdiv == 1 ? '+' : '↱'; printf '%0*X', $coldigits, $_ * $colsize for 0 .. $cols - 1; print "\n"; } print '
%X', ($msb + int($row->{offset} / $cols)) * $cols * $colsize; - for my $lsb (0 .. $cols - 1) { - my $val = ( ($msb * $cols) + $lsb ) * $colsize; + while ($offset < $endpoint - 1) { + print '
'; + { + if (my $rowmod = $offset % $rowdiv) { + # offset in column units + printf '+%X', $rowmod; + } + else { + # divided row offset + printf '%X', ($offset + $row->{offset}) / $rowdiv; + } + } + for (1 .. $cols) { if ($row->{cell}) { - print range_cell($row->{cell}, $val); + print range_cell($row, $offset); next; } - my $glyph = substr $row->{table}, $val, 1; + my $glyph = substr $row->{table}, $offset, 1; if ($glyph eq $NOCHAR) { print ''; next; @@ -185,6 +203,9 @@ for my $row (@request) { print "\n".$glyphs->glyph_cell($glyph); } + continue { + $offset += $colsize; + } print "\n"; } say '
';