charset: unicode zone allocations for plane 1
[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         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.</p>\n",
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         printf "<p>%s</p>\n", join('<br>', map { $_ ? EscapeHTML($_) : () }
45                 $fontmeta->{copyright}, $fontmeta->{license},
46         );
47
48         require Shiar_Sheet::FormatChar;
49         my $glyphs = Shiar_Sheet::FormatChar->new;
50
51         my %cover = map { ($_ => 1) } @cover;  # lookup map
52
53         say <<"EOT";
54
55 <style>
56         .glyphs tbody th[!colspan] { text-align: right }
57         .glyphs tbody td { font-family: "$fontmeta->{name}" }
58         .glyphs tbody td:nth-child(18) { border-left-width: 2px }
59 </style>
60 EOT
61         say '<table class="glyphs big">';
62
63         say "<caption>$_</caption>" for join(' ', grep {$_}
64                 $offset > $pagerows && sprintf('<a rel="start" href="?q=%d">◄</a>', 0),
65                 $offset > 0 && sprintf(
66                         '<a rel="prev" href="?q=%d" title="U+%1$04X">◅</a>',
67                         $offset - $pagerows,
68                 ),
69                 sprintf('U+%04X', $offset),
70                 Unicode::UCD::charblock($offset),
71                 $offset + $pagerows < 0x11_0000 && sprintf(
72                         '<a rel="next" href="?q=%d" title="U+%1$04X">▻</a>',
73                         $offset + $pagerows,
74                 ),
75         );
76
77         for my $cp ($offset .. $offset+$pagerows-1) {
78                 state $colpos;
79                 my $block = Unicode::UCD::charblock($cp);
80                 if ($block ne (state $sameblock = $block) and $block ne 'No_Block') {
81                         print '<tbody>';
82                         printf '<tr><th colspan=%d>%s', $pagecols+1, $block
83                                 unless $block eq 'No_Block';
84                         say '';
85                         $sameblock = $block;
86                         $colpos = 0;
87                 }
88
89                 say sprintf '<tr><th>%X', $cp if $colpos++ % $pagecols == 0;
90
91                 my $info = $glyphs->glyph_info($cp);
92                 my ($class, $name, $mnem, $html, $string) = @{$info};
93                 my $np = $class =~ /\bC\S\b/;  # noprint if control or invalid
94                 say sprintf '<td class="%s" title="U+%04X%s">%s',
95                         !$class ? ('l0', $cp, '', '') :
96                         $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
97                         $cp, !!$name && ": $name",
98                         ($cover{$cp} || !$np) && EscapeHTML(chr $cp);
99         }
100         say '</table>';
101
102         exit;
103 }
104
105 :>
106 <h1>Font coverage</h1>
107
108 <p>
109 Character support of Unicode
110 <a href="/charset">blocks</a> and <a href="/unicode">presets</a>.
111 </p>
112
113 <div>
114
115 <:
116
117 my $cover = do 'unicode-cover.inc.pl' or die $@ || $!;
118
119 my @ossel = @{ $cover->{osdefault} };
120 my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
121
122 my @rows = (
123         'block/Latin-1 Supplement',
124         'block/Latin Extended-A',
125         'block/Latin Extended Additional',
126         'block/Latin Extended-B',
127         'script/Latin',
128         'script/Greek',
129         'script/Cyrillic',
130         'script/Arabic',
131         'script/Hebrew',
132         'script/Devanagari',
133         'script/Thai',
134         'script/Hangul',
135         'table/japanese',
136         'script/Han',
137         'table/ipa',
138         'table/punctuation',
139         'block/Dingbats',
140         'table/symbols',
141         'category/Sc', # currency
142         'table/math',
143         'category/Sm', # mathematical
144         'table/arrows/single',
145         'table/lines/single',
146         'table/block',
147         'table/lines',
148         'table/html',
149 );
150
151 if (my $group = $get{q}) {
152         my $grouprows = $cover->{$group}
153                 or die "Unknown character category $_\n";
154         @rows = map { "$group/$_" } sort keys %{$grouprows};
155 }
156
157 # output character list
158
159 print '<table class=mapped>';
160 print '<col><col>';
161 print "<colgroup span=$_>"
162         for map { scalar @{ $cover->{os}->{$_} } } @ossel;
163
164 print '<thead><tr>';
165 print '<th colspan=2>';
166 printf '<td colspan=%d>%s fonts', scalar @{ $cover->{os}->{$_} }, $_
167         for @ossel;
168
169 print '<tr>';
170 print '<th colspan=2>';
171 printf('<td title="%s"><a href="%s">%s</a>', map { EscapeHTML($_) }
172         join("\n", $_->{name}, $_->{description}),
173         "/font/$_->{file}",
174         $_->{abbr},
175 ) for @{ $cover->{fonts} }[@fontlist];
176 say '</thead>';
177
178 for (@rows) {
179         my ($group, $name) = split m{/}, $_, 2;
180         my $row = $cover->{$group}->{$name};
181
182         print '<tr>';
183         $name = sprintf '<a href="%s">%s</a>', EncodeURI("/chars/$group/$name"), EscapeHTML($name)
184                 if $row->{count} and $row->{count} < 1280;
185         print '<th>', $name;
186         print '<td class=right>', $row->{count};
187         for my $count (@{ $row->{support} }[@fontlist]) {
188                 if (not defined $count) {
189                         print '<td class="l0">?';
190                         next;
191                 }
192                 if (not $count) {
193                         print '<td class="l1">✘';
194                         next;
195                 }
196                 if ($count == $row->{count}) {
197                         print '<td class="l5">✔';
198                         next;
199                 }
200
201                 my $rel = $count / $row->{count};
202                 my $class = $rel < .5 ? 2 : $rel < .9 ? 3 : 4;
203                 printf '<td class="%s">%d%%', "l$class", $rel*100;
204         }
205         say '</tr>';
206 }
207
208 say "</table>\n";
209
210 :></div>
211