c36615db37acc4abe6a11a6035816bf19336f4e7
[sheet.git] / chars.plp
1 <(common.inc.plp)><:
2
3 Html({
4         title => 'character support sheet',
5         version => 'v1.0',
6         keywords => [qw'
7                 unicode glyph char character reference common ipa symbol sign mark table digraph
8         '],
9         stylesheet => [qw'light dark mono circus red'],
10         data => [qw( unicode-cover.inc.pl ttfsupport unicode-char.inc.pl )],
11 });
12
13 :>
14 <h1>Character support</h1>
15
16 <p>
17 Selected characters from Unicode <a href="/unicode">preset</a>
18 or <a href="/charset">range</a>.
19 </p>
20
21 <div>
22
23 <:
24 use 5.010;
25 use Shiar_Sheet::FormatChar;
26 my $glyphs = Shiar_Sheet::FormatChar->new;
27
28 my %oslist = (
29         win95   => [qw( arial ariuni verdana times )],  # microsoft
30         mac10   => [qw( )],  # apple
31         android => [qw( droidsans )],  # google
32         oss     => [qw( dvsans c2k unifont )],
33 );
34 my @ossel = qw( win95 oss android );
35
36 my (%font, @fontlist);
37 for my $os (@ossel) {
38         my $osfonts = $oslist{$os};
39         for my $fontid (@{$osfonts}) {
40                 push @fontlist, $fontid;
41                 my ($fontmeta, @fontrange) = do "ttfsupport/$fontid.inc.pl";
42                 $fontmeta or next;
43                 $font{$fontid} = {
44                         -id   => $fontmeta->{id} || $fontid,
45                         -name => $fontmeta->{name},
46                         map { (chr $_ => 1) } @fontrange
47                 };
48         }
49 }
50
51 # parse input
52
53 my @chars;
54 my @querydesc;
55
56 if (my $query = $ENV{PATH_INFO} || $get{q} || 'ipa') {
57         my $groupinfo = do 'unicode-cover.inc.pl' or die $@ || $!;
58         for (split /[\s+]/, $query) {
59                 s{^/}{};
60                 when (qr{^[\d,;\s+-]+$}) {
61                         push @querydesc, "character codepoints $_";
62                         for (map { split /[^\d-]/ } $_) {
63                                 my ($charnum, $range) = split /-/, $_;
64                                 push @chars, chr $_ for $charnum .. ($range // $charnum);
65                         }
66                 }
67                 when ($_) {
68                         my $row = $groupinfo->{$_} or do {
69                                 warn "group $_ not found";
70                                 next;
71                         };
72                         push @querydesc, $row->{-name} // $_;
73                         push @chars, map { chr } @{ $row->{-chars} };
74                 }
75                 default {
76                         die "unknown parameter: $_\n";
77                 }
78         }
79 }
80
81 @chars <= 1500 or die sprintf(
82         'too many matches (%d) for %s'."\n",
83         scalar @chars, join(', ', @querydesc),
84 );
85
86 # output character list
87
88 print '<table class=mapped>';
89 say '<caption>'.EscapeHTML(join ', ', @querydesc).'</caption>';
90 print '<col>' x 3;
91 print "<colgroup span=$_>" for 2, map { scalar @{$oslist{$_}} } @ossel;
92
93 print '<thead><tr>';
94 print '<td colspan=3>character';
95 print '<td colspan=2>input';
96 printf '<td colspan=%d>%s fonts', scalar @{ $oslist{$_} }, $_
97         for @ossel;
98
99 print '<tr>';
100 print '<td colspan=2>unicode';
101 print '<td>name';
102 print '<td><a href="/digraphs" title="digraph">di</a><td>html';
103 printf '<td title="%s">%s', $font{$_}->{-name}, $font{$_}->{-id} // $_
104         for @fontlist;
105 say '</thead>';
106
107 for my $chr (@chars) {
108         my $codepoint = ord $chr;
109         my $ascii = $codepoint <= 127;
110
111         print "<tr><th>$chr\n";
112         my $info = $glyphs->glyph_info($codepoint);
113         my ($class, $name, $mnem, $html, $string) = @$info;
114         print "<td>$_" for sprintf('%X', $codepoint), EscapeHTML($name || '?');
115         printf '<td class="%s">%s', @$_ for (
116                 [$ascii ? 'l0' : defined $mnem ? $class =~ /\bu-di\b/ ? 'l4' : 'l3' : 'l1', $mnem // ''],
117                 [$ascii ? 'l0' : defined $html ? 'l4' : 'l1', $html // ''],
118                 (map {
119                         !$font{$_}->{-id} ? [l0 => '?'] :
120                         $font{$_}->{$chr} ? [l4 => '✔'] : [l1 => '✘']
121                 } @fontlist),
122         );
123 }
124
125 say "</table>\n";
126
127 :></div>
128