f9b7ac6501326b32ecaec92ada1e810790852a42
[sheet.git] / font.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-table.inc.pl 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 )],
30         mac10 => [qw( )],
31         oss   => [qw( dvsans droid c2k guf )],
32
33         android => ['droid'],
34 );
35 my @ossel = qw(win95 oss);
36
37 my $tables = do 'unicode-table.inc.pl' or die $@ || $!;
38 my (%font, @fontlist);
39 for my $os (@ossel) {
40         my $osfonts = $oslist{$os};
41         for my $fontid (@{$osfonts}) {
42                 push @fontlist, $fontid;
43                 my ($fontmeta, @fontrange) = do "ttfsupport/$fontid.inc.pl";
44                 $fontmeta or next;
45                 $font{$fontid} = {
46                         -id   => $fontmeta->{id} || $fontid,
47                         -name => $fontmeta->{name},
48                         map { (chr $_ => 1) } @fontrange
49                 };
50         }
51 }
52
53 # parse input
54
55 my @chars;
56
57 for ($ENV{PATH_INFO} || $get{q} || ()) {
58         s{^/}{};
59         when ('') {
60                 next;
61         }
62         when (qr{/}) {
63                 push @{ $get{'@g'} }, $_;
64         }
65         default {
66                 die "unknown parameter: $_\n";
67         }
68 }
69
70 $get{'@g'} //= ['latin/sample'];
71
72 for (map { split / / } @{ $get{'@g'} }) {
73         my ($tablegroup, $tablename) = split m{/}, $_, 2;
74         my $table = $tables->{$tablegroup}->{$tablename};
75
76         for (@{$table}) {
77                 m/^[.]/ .. 1 or next;
78                 next if /^[.-]/;
79                 next if $_ eq '>' or $_ eq '=';
80                 push @chars, $_;
81         }
82 }
83
84 # output character list
85
86 print '<table class=mapped>';
87 print '<col>' x 3;
88 print "<colgroup span=$_>" for 2, map { scalar @{$oslist{$_}} } @ossel;
89
90 print '<thead><tr>';
91 print '<td colspan=3>character';
92 print '<td colspan=2>input';
93 printf '<td colspan=%d>%s fonts', scalar @{ $oslist{$_} }, $_
94         for @ossel;
95
96 print '<tr>';
97 print '<td colspan=2>unicode';
98 print '<td>name';
99 print '<td>di<td>html';
100 printf '<td title="%s">%s', $font{$_}->{-name}, $font{$_}->{-id} // $_
101         for @fontlist;
102 say '</thead>';
103
104 for my $chr (@chars) {
105         my $codepoint = ord $chr;
106         my $ascii = $codepoint <= 127;
107
108         print "<tr><th>$chr\n";
109         my $info = $glyphs->glyph_info($codepoint);
110         my ($class, $name, $mnem, $html, $string) = @$info;
111         print "<td>$_" for sprintf('%X', $codepoint), EscapeHTML($name);
112         printf '<td class="%s">%s', @$_ for (
113                 [$ascii ? 'l0' : defined $mnem ? 'l4' : 'l1', $mnem // ''],
114                 [$ascii ? 'l0' : defined $html ? 'l4' : 'l1', $html // ''],
115                 (map {
116                         !$font{$_}->{-id} ? [l0 => '?'] :
117                         $font{$_}->{$chr} ? [l4 => '✔'] : [l1 => '✘']
118                 } @fontlist),
119         );
120 }
121
122 say "</table>\n";
123
124 :></div>
125