6 title => 'font coverage '.($font ? "for $font" : 'sheet'),
9 unicode font glyph char character support overview cover coverage
10 script block symbol sign mark reference table
12 data => [qw( data/unicode-cover.inc.pl )],
16 my $fontmeta = eval { Data("data/font/$font") }
17 or Abort("Unknown font $font", '404 font not found', ref $@ && $@->[1]);
22 my $groupinfo = Data('data/unicode-cover');
24 my ($cat, $name) = split m{/}, $get{map}, 2 or die "invalid map\n";
26 ($cat, $name) = ('table', $cat);
29 my $row = $groupinfo->{$cat}->{$name}
30 or die "unknown character group $cat/$name\n";
31 my $query = $row->{query};
34 for (map { split /[^\d-]/ } $query) {
35 my @range = split /-/, $_, 2;
36 m/^[0-9]+$/ or die "Invalid code point $_ in query $query\n" for @range;
37 push @map, $_ for $range[0] .. ($range[1] // $range[0]);
41 Abort($@, '404 invalid query') if $@;
48 local $_ = $get{q} || 0;
49 return $_ if /\A\d+\z/; # numeric
50 return hex $1 if /\A (?: 0?x | u\W* ) ([0-9a-f]+) \z/ix; # hexadecimal
51 return $_->[0]->[0] for Unicode::UCD::charblock(ucfirst) || (); # block
52 die "Unknown offset query '$_'\n";
54 Abort($@, '400 invalid offset') if $@;
56 say "<h1>Font coverage</h1>";
57 say "<h2>$_</h2>" for EscapeHTML($fontmeta->{name});
58 printf("<p>Version <strong%s>%s</strong> released %s contains %d glyphs.",
59 !!$_->[2] && qq( title="revision $_->[2]"),
61 scalar @{ $fontmeta->{cover} },
64 ($fontmeta->{date} || '?') =~ s/T.*//r,
65 EscapeHTML($fontmeta->{version}),
66 $fontmeta->{revision},
68 for ($fontmeta->{os}) {
70 print ucfirst join(' ',
72 (map { "by $_" } $fontmeta->{oscorp} || "various sources"),
73 (map { "with <em>$_</em>" } $_ || ()),
74 ('and published as freeware "Core Web font"') x ($_ eq 'Windows 2000'),
75 (map { "under a $_ license" }
76 map { $fontmeta->{license} ? qq(<a href="$fontmeta->{license}" rel=nofollow>$_</a>) : $_ }
77 $_ && $_ ne 'Android' ? 'proprietary' : 'free',
83 say "<p>$_</p>" for EscapeHTML($fontmeta->{copyright}) || ();
85 require Shiar_Sheet::FormatChar;
86 my $glyphs = Shiar_Sheet::FormatChar->new;
88 my %cover = map { ($_ => 1) } @{ $fontmeta->{cover} }; # lookup map
93 .glyphs tbody th[!colspan] { text-align: right }
94 .glyphs tbody td { font-family: "$fontmeta->{name}" }
95 .glyphs tbody td:nth-child(18) { border-left-width: 2px }
97 font-family: "$fontmeta->{name}";
98 src: url(/data/font/$font.ttf);
102 say '<table class="glyphs big">';
104 my $offsetlink = '?' . join('&',
105 (map { $_ . '=' . EncodeURI($get{$_}) } grep { defined $get{$_} } qw{ map }),
108 say "<caption>$_</caption>" for join(' ', grep {$_}
109 $offset > $pagerows && sprintf('<a rel="start" href="%s=%d">◄</a>', $offsetlink, 0),
110 $offset > 0 && sprintf(
111 '<a rel="prev nofollow" href="%s=%d" title="U+%2$04X">◅</a>',
112 $offsetlink, $offset - $pagerows,
114 sprintf('U+%04X', $map ? $map->[$offset] : $offset),
115 Unicode::UCD::charblock($map ? $map->[$offset] : $offset),
116 $offset + $pagerows < ($map ? @{$map} : 0x11_0000) && sprintf(
117 '<a rel="next nofollow" href="%s=%d" title="U+%2$04X">▻</a>',
118 $offsetlink, $offset + $pagerows,
122 for my $cp ($offset .. $offset+$pagerows-1) {
123 $cp = $map->[$cp] or next if $map;
126 my $block = Unicode::UCD::charblock($cp);
127 if ($block ne (state $sameblock = $block) and $block ne 'No_Block') {
129 printf '<tr><th colspan=%d>%s', $pagecols+1, $block
130 unless $block eq 'No_Block';
137 # compare previous code point and indicate gaps
139 if ($cp != ++$lastcp) {
140 if (!$colpos or $colpos++ % $pagecols > $pagecols - 3) {
141 # nearly last column, start new row
145 # mark repositioning in existing row
146 printf '<th>%X', $cp;
152 say sprintf '<tr><th>%X', $cp if $colpos++ % $pagecols == 0;
154 my $info = $glyphs->glyph_info($cp);
155 my ($class, $name, $mnem, $entity, $string) = @{$info};
156 my $np = $class =~ /\bC\S\b/; # noprint if control or invalid
157 # display literal character, with placeholder circle if non-spacing/enclosing
158 $string ||= ($class =~ /\bM[ne]\b/ && chr 9676) . chr($cp);
159 my $html = $np ? !!$cover{$cp} && sprintf("&#%d;", $cp) :
161 say sprintf '<td class="%s" title="U+%04X%s">%s',
162 !$class ? ('l0', $cp, '', '') : (
163 $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
164 $cp, !!$name && ": $name",
174 <h1>Font coverage</h1>
177 Character support of Unicode
178 <a href="/charset">blocks</a> and <a href="/unicode">presets</a>.
185 my $cover = Data('data/unicode-cover');
187 my @ossel = @{ $cover->{osdefault} };
188 my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
193 'block/Latin-1 Supplement',
194 'block/Latin Extended-A',
195 'block/Latin Extended Additional',
196 'block/Latin Extended-B',
211 'category/Sc', # currency
213 'category/Sm', # mathematical
214 'table/arrows/single',
215 'table/lines/single',
221 if (my $group = $get{q}) {
222 my $grouprows = $cover->{$group}
223 or Abort("Unknown character category $_", 404);
224 @rows = map { "$group/$_" } sort keys %{$grouprows};
227 # output character list
229 print '<table class="mapped cover">';
231 print "<colgroup span=$_>"
232 for map { scalar @{ $cover->{os}->{$_} } } @ossel;
235 print '<th colspan=2>';
236 for my $os (@ossel) {
237 my $osfonts = $cover->{os}->{$os};
238 my $osfont = $cover->{fonts}->[ $osfonts->[0] ]; # first font
239 printf '<td colspan=%d>%s', scalar @{$osfonts}, $osfont->{os} || ''
243 print '<th colspan=2>';
244 printf('<td title="%s"><a href="%s">%s</a>', map { EscapeHTML($_) }
245 join("\n", $_->{name}, $_->{description}),
248 ) for @{ $cover->{fonts} }[@fontlist];
252 my ($group, $name) = split m{/}, $_, 2;
253 my $row = $cover->{$group}->{$name};
256 $name = sprintf 'Unicode v%.1f', $name / 10 if $group eq 'version';
257 $name = sprintf '<a href="%s">%s</a>', EncodeURI("/chars/$group/$name"), EscapeHTML($name)
258 if $row->{count} and $row->{count} < 1280;
260 print '<td class=right>', $row->{count};
261 for my $count (@{ $row->{support} }[@fontlist]) {
262 if (not defined $count) {
263 print '<td class="l0">?';
267 print '<td class="l1">✘';
270 if ($count == $row->{count}) {
271 print '<td class="l5">✔';
275 my $rel = $count / $row->{count};
276 my $class = $rel < .5 ? 2 : $rel < .9 ? 3 : 4;
277 printf '<td class="%s">%d', "l$class", $rel*10;