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