<(common.inc.plp)><:
Html({
title => 'character support sheet',
version => '1.2',
keywords => [qw'
unicode glyph char character reference common ipa symbol sign mark table digraph
'],
data => [qw( data/unicode-cover.inc.pl data/font data/unicode-char.inc.pl )],
raw => <<'EOT',
<style>
tbody tr:hover th {
font-size: 300%;
min-width: 1.2em;
border-width: 1px;
}
</style>
EOT
});
use Shiar_Sheet::FormatChar;
my $glyphs = Shiar_Sheet::FormatChar->new;
my $groupinfo = Data('data/unicode-cover');
my @ossel = @{ $groupinfo->{osdefault} };
my @fontlist = map { $_->{file} }
@{ $groupinfo->{fonts} }[ map { @{ $groupinfo->{os}->{$_} } } @ossel ];
my %font;
for my $fontid (@fontlist) {
my $fontmeta = eval { Data("data/font/$fontid") } or next;
$font{$fontid} = {
(map { (-$_ => $fontmeta->{$_}) } keys %{$fontmeta}),
map { (chr $_ => 1) } @{ $fontmeta->{cover} }
};
}
my ($title, $parent) = ('Character overview');
my $query = eval {
for ($Request || ()) {
return $_ if m{^[0-9 +-]+$};
my ($cat, $name) = split m{/}, $_, 2 or die "invalid query\n";
if (!$name) {
($cat, $name) = ('table', $cat);
}
my $row = $groupinfo->{$cat}->{$name}
or die "unknown character group $cat/$name\n";
$title = ucfirst EscapeHTML($name).' characters';
$parent = $cat;
return EscapeHTML($row->{query});
}
} || $get{q};
say "<h1>$title</h1>";
if (!$query) {
Abort(["Unicode group not found", $@], '404 no matches');
};
for ($parent || 'Unicode range') {
my %CATDESC = (
block => '<a href="/charset/unicode">Unicode block</a>',
script => 'Unicode script',
category => 'Unicode category',
table => '<a href="/unicode">Unicode preset group</a>',
);
say sprintf('<p>List %s in selected %s.</p>',
'characters and <a href="/font">font support</a>',
$CATDESC{$parent} || $parent,
);
}
my @chars;
for (map { split /[^\d-]/ } $query) {
my @range = split /-/, $_, 2;
m/^[0-9]+$/ or Abort("Invalid code point $_ in query $query", 400)
for @range;
push @chars, chr $_ for $range[0] .. ($range[1] // $range[0]);
}
@chars or Abort("No match for query $query", '404 no results');
@chars <= 1500 or Abort(
sprintf('Too many matches (%d) for query', scalar @chars),
'403 not allowed', $query
);
say '<div>';
print '<table class="mapped cover">';
print '<col>' x 3;
print "<colgroup span=$_>"
for 2, map { scalar @{ $groupinfo->{os}->{$_} } } @ossel;
print '<thead><tr>';
print '<td colspan=3>character';
print '<td colspan=2>input';
printf '<td colspan=%d>%s', scalar @{ $groupinfo->{os}->{$_} }, $_
for @ossel;
print '<tr>';
print '<td colspan=2>unicode';
print '<td>name';
print '<td><a href="/digraphs" title="digraph">di</a><td>html';
printf('<td title="%s">%s', map { EscapeHTML($_) }
join("\n", $font{$_}->{-name}, $font{$_}->{-description}),
$font{$_}->{-abbr},
) for @fontlist;
say '</thead>';
for my $chr (@chars) {
my $codepoint = ord $chr;
my $ascii = $codepoint <= 127;
say '<tr><th>', $chr;
my $info = $glyphs->glyph_info($codepoint);
my ($class, $name, $mnem, $entity, $string) = @$info;
print "<td>$_" for sprintf('%X', $codepoint), EscapeHTML($name || '?');
printf '<td class="%s">%s', @$_ for (
[$ascii ? 'l0' : defined $mnem ? $class =~ /\bu-di\b/ ? 'l4' : 'l3' : 'l1',
EscapeHTML($mnem) // ''],
[$ascii ? 'l0' : defined $entity ? 'l4' : 'l1', $entity // ''],
(map {
!defined $font{$_}->{-name} ? [l0 => '?'] :
$font{$_}->{$chr} ? [l4 => '✔'] : [l1 => '✘']
} @fontlist),
);
}
say "</table>\n";
say "</div>\n";