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