font: mkttfinfo: strip file extensions from 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         .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                 # display literal character, with placeholder circle if non-spacing/enclosing
95                 my $html = ($class =~ /\bM[ne]\b/ && chr 9676) . EscapeHTML(chr $cp);
96                 say sprintf '<td class="%s" title="U+%04X%s">%s',
97                         !$class ? ('l0', $cp, '', '') :
98                         $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
99                         $cp, !!$name && ": $name",
100                         ($cover{$cp} || !$np) && $html;
101         }
102         say '</table>';
103
104         exit;
105 }
106
107 :>
108 <h1>Font coverage</h1>
109
110 <p>
111 Character support of Unicode
112 <a href="/charset">blocks</a> and <a href="/unicode">presets</a>.
113 </p>
114
115 <div>
116
117 <:
118
119 my $cover = do 'unicode-cover.inc.pl' or die $@ || $!;
120
121 my @ossel = @{ $cover->{osdefault} };
122 my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
123
124 my @rows = (
125         'version/11',
126         'version/63',
127         'block/Latin-1 Supplement',
128         'block/Latin Extended-A',
129         'block/Latin Extended Additional',
130         'block/Latin Extended-B',
131         'script/Latin',
132         'script/Greek',
133         'script/Cyrillic',
134         'script/Arabic',
135         'script/Hebrew',
136         'script/Devanagari',
137         'script/Thai',
138         'script/Hangul',
139         'table/japanese',
140         'script/Han',
141         'table/ipa',
142         'table/punctuation',
143         'block/Dingbats',
144         'table/symbols',
145         'category/Sc', # currency
146         'table/math',
147         'category/Sm', # mathematical
148         'table/arrows/single',
149         'table/lines/single',
150         'table/block',
151         'table/lines',
152         'table/html',
153 );
154
155 if (my $group = $get{q}) {
156         my $grouprows = $cover->{$group}
157                 or die "Unknown character category $_\n";
158         @rows = map { "$group/$_" } sort keys %{$grouprows};
159 }
160
161 # output character list
162
163 print '<table class=mapped>';
164 print '<col><col>';
165 print "<colgroup span=$_>"
166         for map { scalar @{ $cover->{os}->{$_} } } @ossel;
167
168 print '<thead><tr>';
169 print '<th colspan=2>';
170 printf '<td colspan=%d>%s fonts', scalar @{ $cover->{os}->{$_} }, $_
171         for @ossel;
172
173 print '<tr>';
174 print '<th colspan=2>';
175 printf('<td title="%s"><a href="%s">%s</a>', map { EscapeHTML($_) }
176         join("\n", $_->{name}, $_->{description}),
177         "/font/$_->{file}",
178         $_->{abbr},
179 ) for @{ $cover->{fonts} }[@fontlist];
180 say '</thead>';
181
182 for (@rows) {
183         my ($group, $name) = split m{/}, $_, 2;
184         my $row = $cover->{$group}->{$name};
185
186         print '<tr>';
187         $name = sprintf 'Unicode v%.1f', $name / 10 if $group eq 'version';
188         $name = sprintf '<a href="%s">%s</a>', EncodeURI("/chars/$group/$name"), EscapeHTML($name)
189                 if $row->{count} and $row->{count} < 1280;
190         print '<th>', $name;
191         print '<td class=right>', $row->{count};
192         for my $count (@{ $row->{support} }[@fontlist]) {
193                 if (not defined $count) {
194                         print '<td class="l0">?';
195                         next;
196                 }
197                 if (not $count) {
198                         print '<td class="l1">✘';
199                         next;
200                 }
201                 if ($count == $row->{count}) {
202                         print '<td class="l5">✔';
203                         next;
204                 }
205
206                 my $rel = $count / $row->{count};
207                 my $class = $rel < .5 ? 2 : $rel < .9 ? 3 : 4;
208                 printf '<td class="%s">%d%%', "l$class", $rel*100;
209         }
210         say '</tr>';
211 }
212
213 say "</table>\n";
214
215 :></div>
216