sc: encode hots bonus damage in data
[sheet.git] / font.plp
1 <(common.inc.plp)><:
2 use 5.014;
3
4 Html({
5         title => 'character support sheet',
6         version => 'v1.2',
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         require Unicode::UCD;
20
21         my $pagerows = 0x200;
22         my $pagecols = 32;
23         my $offset = eval {
24                 local $_ = $get{q} || 0;
25                 return $_ if /\A\d+\z/;  # numeric
26                 return hex $1 if /\A (?: 0?x | u\W* ) ([0-9a-f]+) \z/ix;  # hexadecimal
27                 return $_->[0]->[0] for Unicode::UCD::charblock(ucfirst) || ();  # block
28                 die "Unknown offset query '$_'\n";
29         };
30         die $@ if $@;
31
32         say "<h1>Font coverage</h1>";
33         say "<h2>$_</h2>" for EscapeHTML($fontmeta->{name});
34         printf("<p>Version <strong%s>%s</strong> released %s contains %d glyphs.",
35                 !!$_->[2] && qq( title="revision $_->[2]"),
36                 $_->[1], $_->[0],
37                 scalar @cover,
38         ) for [
39                 grep { $_ }
40                 ($fontmeta->{date} || '?') =~ s/T.*//r,
41                 EscapeHTML($fontmeta->{version}),
42                 $fontmeta->{revision},
43         ];
44         for ($fontmeta->{os}) {
45                 say '<br>';
46                 print ucfirst join(' ',
47                         "distributed",
48                         (map { "by $_" } $fontmeta->{oscorp} || "various sources"),
49                         (map { "with <em>$_</em>" } $_ || ()),
50                         ('and published as freeware "Core Web font"') x ($_ eq 'Windows 2000'),
51                         (map { "under a $_ license" }
52                                 map { $fontmeta->{license} ? qq(<a href="$fontmeta->{license}">$_</a>) : $_ }
53                                 $_ && $_ ne 'Android' ? 'proprietary' : 'free',
54                         ),
55                 );
56                 print '.';
57         }
58         say '</p>';
59         say "<p>$_</p>" for EscapeHTML($fontmeta->{copyright}) || ();
60
61         require Shiar_Sheet::FormatChar;
62         my $glyphs = Shiar_Sheet::FormatChar->new;
63
64         my %cover = map { ($_ => 1) } @cover;  # lookup map
65
66         say <<"EOT";
67
68 <style>
69         .glyphs tbody th[!colspan] { text-align: right }
70         .glyphs tbody td { font-family: "$fontmeta->{name}" }
71         .glyphs tbody td:nth-child(18) { border-left-width: 2px }
72         \@font-face {
73                 font-family: "$fontmeta->{name}";
74                 src: url(/data/font/$font.ttf);
75         }
76 </style>
77 EOT
78         say '<table class="glyphs big">';
79
80         say "<caption>$_</caption>" for join(' ', grep {$_}
81                 $offset > $pagerows && sprintf('<a rel="start" href="?q=%d">◄</a>', 0),
82                 $offset > 0 && sprintf(
83                         '<a rel="prev" href="?q=%d" title="U+%1$04X">◅</a>',
84                         $offset - $pagerows,
85                 ),
86                 sprintf('U+%04X', $offset),
87                 Unicode::UCD::charblock($offset),
88                 $offset + $pagerows < 0x11_0000 && sprintf(
89                         '<a rel="next" href="?q=%d" title="U+%1$04X">▻</a>',
90                         $offset + $pagerows,
91                 ),
92         );
93
94         for my $cp ($offset .. $offset+$pagerows-1) {
95                 state $colpos;
96                 my $block = Unicode::UCD::charblock($cp);
97                 if ($block ne (state $sameblock = $block) and $block ne 'No_Block') {
98                         print '<tbody>';
99                         printf '<tr><th colspan=%d>%s', $pagecols+1, $block
100                                 unless $block eq 'No_Block';
101                         say '';
102                         $sameblock = $block;
103                         $colpos = 0;
104                 }
105
106                 say sprintf '<tr><th>%X', $cp if $colpos++ % $pagecols == 0;
107
108                 my $info = $glyphs->glyph_info($cp);
109                 my ($class, $name, $mnem, $html, $string) = @{$info};
110                 my $np = $class =~ /\bC\S\b/;  # noprint if control or invalid
111                 # display literal character, with placeholder circle if non-spacing/enclosing
112                 my $html = ($class =~ /\bM[ne]\b/ && chr 9676) . EscapeHTML(chr $cp);
113                 say sprintf '<td class="%s" title="U+%04X%s">%s',
114                         !$class ? ('l0', $cp, '', '') :
115                         $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
116                         $cp, !!$name && ": $name",
117                         ($cover{$cp} || !$np) && $html;
118         }
119         say '</table>';
120
121         exit;
122 }
123
124 :>
125 <h1>Font coverage</h1>
126
127 <p>
128 Character support of Unicode
129 <a href="/charset">blocks</a> and <a href="/unicode">presets</a>.
130 </p>
131
132 <div>
133
134 <:
135
136 my $cover = do 'unicode-cover.inc.pl' or die $@ || $!;
137
138 my @ossel = @{ $cover->{osdefault} };
139 my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
140
141 my @rows = (
142         'version/11',
143         'version/63',
144         'block/Latin-1 Supplement',
145         'block/Latin Extended-A',
146         'block/Latin Extended Additional',
147         'block/Latin Extended-B',
148         'script/Latin',
149         'script/Greek',
150         'script/Cyrillic',
151         'script/Arabic',
152         'script/Hebrew',
153         'script/Devanagari',
154         'script/Thai',
155         'script/Hangul',
156         'table/japanese',
157         'script/Han',
158         'table/ipa',
159         'table/punctuation',
160         'block/Dingbats',
161         'table/symbols',
162         'category/Sc', # currency
163         'table/math',
164         'category/Sm', # mathematical
165         'table/arrows/single',
166         'table/lines/single',
167         'table/block',
168         'table/lines',
169         'table/html',
170 );
171
172 if (my $group = $get{q}) {
173         my $grouprows = $cover->{$group}
174                 or die "Unknown character category $_\n";
175         @rows = map { "$group/$_" } sort keys %{$grouprows};
176 }
177
178 # output character list
179
180 print '<table class=mapped>';
181 print '<col><col>';
182 print "<colgroup span=$_>"
183         for map { scalar @{ $cover->{os}->{$_} } } @ossel;
184
185 print '<thead><tr>';
186 print '<th colspan=2>';
187 for my $os (@ossel) {
188         my $osfonts = $cover->{os}->{$os};
189         my $osfont = $cover->{fonts}->[ $osfonts->[0] ]; # first font
190         printf '<td colspan=%d>%s', scalar @{$osfonts}, $osfont->{os} || ''
191 }
192
193 print '<tr>';
194 print '<th colspan=2>';
195 printf('<td title="%s"><a href="%s">%s</a>', map { EscapeHTML($_) }
196         join("\n", $_->{name}, $_->{description}),
197         "/font/$_->{file}",
198         $_->{abbr},
199 ) for @{ $cover->{fonts} }[@fontlist];
200 say '</thead>';
201
202 for (@rows) {
203         my ($group, $name) = split m{/}, $_, 2;
204         my $row = $cover->{$group}->{$name};
205
206         print '<tr>';
207         $name = sprintf 'Unicode v%.1f', $name / 10 if $group eq 'version';
208         $name = sprintf '<a href="%s">%s</a>', EncodeURI("/chars/$group/$name"), EscapeHTML($name)
209                 if $row->{count} and $row->{count} < 1280;
210         print '<th>', $name;
211         print '<td class=right>', $row->{count};
212         for my $count (@{ $row->{support} }[@fontlist]) {
213                 if (not defined $count) {
214                         print '<td class="l0">?';
215                         next;
216                 }
217                 if (not $count) {
218                         print '<td class="l1">✘';
219                         next;
220                 }
221                 if ($count == $row->{count}) {
222                         print '<td class="l5">✔';
223                         next;
224                 }
225
226                 my $rel = $count / $row->{count};
227                 my $class = $rel < .5 ? 2 : $rel < .9 ? 3 : 4;
228                 printf '<td class="%s">%d%%', "l$class", $rel*100;
229         }
230         say '</tr>';
231 }
232
233 say "</table>\n";
234
235 :></div>
236