-my @request = map {
- if (my $input = $_) {
- my %row = (offset => 0);
- my $endpoint = 255;
- if ($input =~ s/^--//) {
- $row{offset} = $endpoint > 160 ? 160 : 48;
- }
- elsif ($input =~ s/^-//) {
- $row{offset} = $endpoint > 128 ? 128 : 32;
- }
- if ($input =~ s/-$//) {
- $endpoint = $row{offset} ? $row{offset} < 160 ? 159 : 191 : 127;
- }
-
- if ($input =~ /^U([0-9a-f]+)(?:-([0-9a-f]+))?/) {
- my $start = hex($1) << ($2 ? 4 : 8);
- my $end = $2 ? hex($2) << 4 : $start + 240;
- $row{table} = join '', map { chr } $start .. $end+15;
- utf8::upgrade($row{table}); # prevent latin1 output
- $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8;
- }
- elsif ($input eq 'U') {
- $row{table} = ' ' x 512;
- $row{set} = 'Unicode planes';
- $row{cell} = do 'charset-ucplanes.inc.pl';
- }
- elsif ($row{set} = resolve_alias($input)) {
- if ($row{set} eq 'Internal') {
- $row{table} = ' ' x ($endpoint < 255 ? 640 : 4096);
- $row{set} = 'Unicode BMP';
- $row{cell} = do 'charset-unicode.inc.pl';
- }
- elsif ($row{set} eq 'utf-8-strict') {
- $row{table} = undef;
- $row{set} = 'UTF-8';
- $row{cell} = do 'charset-utf8.inc.pl';
+
+}
+:>.
+</p>
+
+<:
+use POSIX qw( ceil );
+use Shiar_Sheet::FormatChar;
+my $glyphs = Shiar_Sheet::FormatChar->new;
+my @request;
+
+my $charsets = do 'charset-encoding.inc.pl'
+ or Alert('Encoding metadata could not be read', $@ || $!);
+
+sub tabinput {
+ # generate character table(s)
+ my $input = shift or return;
+ my $params = $input =~ s/[+](.*)\z// ? $1 : undef;
+ my $charset = $charsets->{lc $input} || {};
+
+ if (ref $charset ne 'HASH') {
+ $params and Alert("Parameters ignored for $input",
+ "Cannot apply <q>$params</q> to multiple charsets.",
+ );
+ tabinput($_) for ref $charset ? @{$charset} : $charset;
+ return;
+ }
+
+ state $visible = {'' => 1}; # all present tables
+ my %row = (offset => 0, cols => 16);
+
+ if (not defined $params) {
+ my @parents = @{ $charset->{inherit} || [] };
+
+ if (my ($parent, $part) = pairfirst { defined $visible->{$a} } @parents) {
+ $row{parent} = $parent;
+ $params = $part;
+ $params = 80 unless $visible->{$parent}
+ or ($input eq 'MacCroatian' and defined $visible->{MacRomanian});
+ }
+ elsif (defined $visible->{ascii}) {
+ $row{parent} = $parents[0];
+ $params = $parents[1] // 80;
+ $params = 80 if hex $params >= 0x80; # ascii offset at most
+ }
+ elsif (@parents) {
+ $row{parent} = $parents[0];
+ $params = $parents[1] if hex $parents[1] == 0; # apply ascii end
+ }
+ $visible->{$_} //= 0 for $row{parent} || ();
+ }
+
+ for my $param (split /[+]+/, $params // '') {
+ if ($param eq 'realsize') {
+ $row{realsize}++;
+ }
+ elsif ($param =~ m{ \A cols = (\d+) \z }x) {
+ $row{cols} = $1;
+ }
+ elsif ($param =~ m{ \A (?<start> \p{AHex}+) (?: [-] (?<end> \p{AHex}+) )? \z }x) {
+ if (defined $row{endpoint}) {
+ # extend earlier range
+ my $skip = int(($row{endpoint} || $row{startpoint}) / $row{cols});
+ for ($skip + 1 .. (hex($+{start}) / $row{cols}) - 1) {
+ $row{skip}->{ $_ * $row{cols} - $row{startpoint} }++;
+ }