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