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