X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/e3e4c296dc5549aea747ecbd01366a372d304261..1b025f386b84705e81bd75c166bf0f08d5891608:/charset.plp
diff --git a/charset.plp b/charset.plp
index 9bdf363..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,8 +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;
- $cols *= 2;
+ $row{cols} *= 2;
}
elsif ($row{set} = Encode::resolve_alias($input)) {
if ($row{set} eq 'Internal') {
@@ -108,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';
@@ -157,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 '%s', $title;
print '' x ($cols + 1);
- my $coldigits = $colsize * $cols <= 16 ? 1 : 2; # uniform length of hexadecimal header
for my $section (qw{thead}) {
- print "<$section>â±";
+ print "<$section> |
---|
", $rowdiv == 1 ? '+' : 'â±';
printf ' | %0*X', $coldigits, $_ * $colsize for 0 .. $cols - 1;
print "\n";
}
print ' |
';
- for my $msb (0 .. ((length($row->{table}) || 256) - 1) / $cols) {
- printf '%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;
@@ -186,6 +203,9 @@ for my $row (@request) {
print "\n".$glyphs->glyph_cell($glyph);
}
+ continue {
+ $offset += $colsize;
+ }
print "\n";
}
say ' |
---|
';