7 use open OUT => ':utf8', ':std';
8 use List::Util 'reduce';
9 use File::Basename 'basename';
12 our $VERSION = '1.00';
15 my $incsuffix = '.inc.pl';
16 for my $fontfile (glob 'ttfsupport/*'.$incsuffix) {
17 my ($fontid) = basename($fontfile, $incsuffix);
18 my ($fontmeta, @fontrange) = do $fontfile or next;
20 -id => $fontmeta->{id} || $fontid,
21 -name => $fontmeta->{name},
22 map { (chr $_ => 1) } @fontrange
26 when (qr{^[a-z]+(?:/|\z)}) {
31 my $chartables = do 'unicode-table.inc.pl' or warn $@ || $!;
33 while (my ($tablegroup, $grouprow) = each %{$chartables}) {
34 while (my ($tablename, $chars) = each %{$grouprow}) {
35 next if $tablename =~ /^-/;
36 my $includerows; # ignore rows before body row
38 $includerows ||= m/^[.]/ or next;
40 next if $_ eq '>' or $_ eq '=';
41 push @{ $charlist{table}->{"$tablegroup/$tablename"} }, $_;
42 push @{ $charlist{table}->{$tablegroup} }, $_;
45 # if ($tablegroup eq 'ipa') {
46 # @chars = grep { !m/[a-zA-Z]/ } @chars;
51 use Unicode::UCD 'charinfo';
52 for my $code (0 .. 256**2) {
53 my $charinfo = charinfo($code) or next;
54 next if $charinfo->{category} =~ /^[MC]/; # ignore Marks and "other" Control chars
55 push @{ $charlist{$_}->{ $charinfo->{$_} } }, chr $code
56 for qw( script category block );
59 for (values %charlist) {
60 for my $chars (values %{$_}) {
62 my $fontcover = $font{$_};
63 ($_ => scalar grep { $fontcover->{$_} } @{$chars});
65 $row{-count} = scalar @{$chars};
68 my @query = map { ord } sort @{$chars};
75 last if $query[$j] != $v;
79 splice(@query, $i, $j - $i, "$query[$i]-$query[$j-1]");
83 return join '+', @query;
91 say '+'.pp(\%charlist);
97 mkfontinfo - Prepare font coverage of various character groups
101 mkfontinfo > unicode-cover.inc.pl
103 Test by finding the number of cyrillic characters in DejaVu Sans:
105 perl -E'$f = do "unicode-cover.inc.pl"; say $f->{Cyrillic}->{dvsans}'
109 Mischa POSLAWSKY <perl@shiar.org>
113 Licensed under the GNU Affero General Public License version 3.