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