font: subpage lists ordered glyphs in requested typeface
[sheet.git] / font.plp
1 <(common.inc.plp)><:
2 use 5.014;
3
4 Html({
5         title => 'character support sheet',
6         version => 'v1.1',
7         keywords => [qw(
8                 unicode font glyph char character support overview cover coverage
9                 script block symbol sign mark reference table
10         )],
11         stylesheet => [qw( light dark mono circus red )],
12         data => [qw( unicode-cover.inc.pl )],
13 });
14
15 if (my $font = $ENV{PATH_INFO} =~ s{^/}{}r) {
16         my ($fontmeta, @cover) = do "ttfsupport/$font.inc.pl";
17         $fontmeta or die "Unknown font $font\n";
18
19         my $offset = $get{q} || 0;
20
21         say "<h1>Font coverage</h1>";
22         say "<h2>$_</h2>" for EscapeHTML($fontmeta->{name});
23         printf("<p>Version <strong%s>%s</strong> released %s contains %d glyphs.</p>\n",
24                 !!$_->[2] && qq( title="revision $_->[2]"),
25                 $_->[1], $_->[0],
26                 scalar @cover,
27         ) for [
28                 grep { $_ }
29                 ($fontmeta->{date} || '?') =~ s/T.*//r,
30                 EscapeHTML($fontmeta->{version}),
31                 $fontmeta->{revision},
32         ];
33         printf "<p>%s</p>\n", join('<br>', map { $_ ? EscapeHTML($_) : () }
34                 $fontmeta->{copyright}, $fontmeta->{license},
35         );
36
37         require Shiar_Sheet::FormatChar;
38         my $glyphs = Shiar_Sheet::FormatChar->new;
39
40         my %cover = map { ($_ => 1) } @cover;  # lookup map
41
42         say <<"EOT";
43
44 <style>
45         .glyphs tbody th { text-align: right }
46         .glyphs tbody td { font-family: "$fontmeta->{name}" }
47 </style>
48 EOT
49         say '<table class="glyphs big">';
50         for my $cp ($offset .. $offset+0x1FF) {
51                 my $info = $glyphs->glyph_info($cp);
52                 my ($class, $name, $mnem, $html, $string) = @{$info};
53                 my $np = $class =~ /\bC\S\b/;  # noprint if control or invalid
54                 say sprintf '<tr><th>%X', $cp if $cp % 32 == 0;
55                 say sprintf '<td class="%s" title="U+%04X%s">%s',
56                         !$class ? ('l0', $cp, '', '') :
57                         $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
58                         $cp, !!$name && ": $name",
59                         ($cover{$cp} || !$np) && EscapeHTML(chr $cp);
60         }
61         say '</table>';
62
63         exit;
64 }
65
66 :>
67 <h1>Font coverage</h1>
68
69 <p>
70 Character support of Unicode
71 <a href="/charset">blocks</a> and <a href="/unicode">presets</a>.
72 </p>
73
74 <div>
75
76 <:
77
78 my $cover = do 'unicode-cover.inc.pl' or die $@ || $!;
79
80 my @ossel = @{ $cover->{osdefault} };
81 my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
82
83 my @rows = (
84         'block/Latin-1 Supplement',
85         'block/Latin Extended-A',
86         'block/Latin Extended Additional',
87         'block/Latin Extended-B',
88         'script/Latin',
89         'script/Greek',
90         'script/Cyrillic',
91         'script/Arabic',
92         'script/Hebrew',
93         'script/Devanagari',
94         'script/Thai',
95         'script/Hangul',
96         'table/japanese',
97         'script/Han',
98         'table/ipa',
99         'table/punctuation',
100         'block/Dingbats',
101         'table/symbols',
102         'category/Sc', # currency
103         'table/math',
104         'category/Sm', # mathematical
105         'table/arrows/single',
106         'table/lines/single',
107         'table/block',
108         'table/lines',
109         'table/html',
110 );
111
112 if (my $group = $get{q}) {
113         my $grouprows = $cover->{$group}
114                 or die "Unknown character category $_\n";
115         @rows = map { "$group/$_" } sort keys %{$grouprows};
116 }
117
118 # output character list
119
120 print '<table class=mapped>';
121 print '<col><col>';
122 print "<colgroup span=$_>"
123         for map { scalar @{ $cover->{os}->{$_} } } @ossel;
124
125 print '<thead><tr>';
126 print '<th colspan=2>';
127 printf '<td colspan=%d>%s fonts', scalar @{ $cover->{os}->{$_} }, $_
128         for @ossel;
129
130 print '<tr>';
131 print '<th colspan=2>';
132 printf('<td title="%s"><a href="%s">%s</a>', map { EscapeHTML($_) }
133         join("\n", $_->{name}, $_->{description}),
134         "/font/$_->{file}",
135         $_->{abbr},
136 ) for @{ $cover->{fonts} }[@fontlist];
137 say '</thead>';
138
139 for (@rows) {
140         my ($group, $name) = split m{/}, $_, 2;
141         my $row = $cover->{$group}->{$name};
142
143         print '<tr>';
144         $name = sprintf '<a href="%s">%s</a>', EncodeURI("/chars/$group/$name"), EscapeHTML($name)
145                 if $row->{count} and $row->{count} < 1280;
146         print '<th>', $name;
147         print '<td class=right>', $row->{count};
148         for my $count (@{ $row->{support} }[@fontlist]) {
149                 if (not defined $count) {
150                         print '<td class="l0">?';
151                         next;
152                 }
153                 if (not $count) {
154                         print '<td class="l1">✘';
155                         next;
156                 }
157                 if ($count == $row->{count}) {
158                         print '<td class="l5">✔';
159                         next;
160                 }
161
162                 my $rel = $count / $row->{count};
163                 my $class = $rel < .5 ? 2 : $rel < .9 ? 3 : 4;
164                 printf '<td class="%s">%d%%', "l$class", $rel*100;
165         }
166         say '</tr>';
167 }
168
169 say "</table>\n";
170
171 :></div>
172