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