7 use open OUT => ':utf8', ':std';
8 use File::Basename 'basename';
11 our $VERSION = '1.01';
16 my $incsuffix = '.inc.pl';
17 for my $fontfile (glob 'ttfsupport/*'.$incsuffix) {
18 my ($fontid) = basename($fontfile, $incsuffix);
19 my ($fontmeta, @fontrange) = do $fontfile or next;
20 $fontmeta->{file} = $fontid;
21 push @fontlist, $fontmeta;
22 $cover{$fontid} = { map { (chr $_ => 1) } @fontrange };
27 my $chartables = do 'unicode-table.inc.pl' or warn $@ || $!;
29 while (my ($tablegroup, $grouprow) = each %{$chartables}) {
30 while (my ($tablename, $chars) = each %{$grouprow}) {
31 next if $tablename =~ /^-/;
32 my $includerows; # ignore rows before body row
34 $includerows ||= m/^[.]/ or next;
36 next if $_ eq '>' or $_ eq '=';
38 length $_ == 1 or next; # multiple characters lost in query
39 push @{ $charlist{table}->{"$tablegroup/$tablename"} }, $_;
40 push @{ $charlist{table}->{$tablegroup} }, $_;
43 # if ($tablegroup eq 'ipa') {
44 # @chars = grep { !m/[a-zA-Z]/ } @chars;
50 require HTML::Entities;
52 HTML::Entities->import('%char2entity');
53 while (my ($char, $entity) = each %char2entity) {
54 $entity =~ /[a-zA-Z]/ or next; # only actual aliases
55 push @{ $charlist{table}->{html} }, $char;
58 } or warn "Could not include count for html entities: $@";
60 use Unicode::UCD 'charinfo';
61 for my $code (0 .. 256**2) {
62 my $charinfo = charinfo($code) or next;
63 next if $charinfo->{category} =~ /^[MC]/; # ignore Marks and "other" Control chars
64 push @{ $charlist{$_}->{ $charinfo->{$_} } }, chr $code
65 for qw( script category block );
68 for (values %charlist) {
69 for my $chars (values %{$_}) {
72 map { scalar grep { defined } @{ $cover{$_->{file}} }{ @{$chars} } }
75 $row{count} = scalar @{$chars};
78 my @query = map { ord } sort @{$chars};
85 last if $query[$j] != $v;
89 splice(@query, $i, $j - $i, "$query[$i]-$query[$j-1]");
93 return join '+', @query;
100 $charlist{fonts} = \@fontlist;
103 win95 => [qw( arial arialuni lucidau verdana timesnew couriernew )], # microsoft
104 mac10 => [qw( helvetica lucida times garamond palatino )], # apple
105 android => [qw( roboto noto )], # google
106 oss => [qw( dvsans c2k unifont opensans )],
108 my %fontnum = map { ($fontlist[$_]->{file} => $_) } 0 .. $#fontlist;
109 while (my ($os, $fontids) = each %osfonts) {
110 $charlist{os}->{$os} = [ map { $fontnum{$_} // () } @{$fontids} ];
112 $charlist{osdefault} = [qw( win95 mac10 oss android )];
114 say "# automatically generated by $0";
116 say '+'.pp(\%charlist);
122 mkfontinfo - Prepare font coverage of various character groups
126 mkfontinfo > unicode-cover.inc.pl
128 Test by finding the number of cyrillic characters in DejaVu Sans:
130 perl -E'$f = do "unicode-cover.inc.pl"; say $f->{Cyrillic}->{dvsans}'
134 Mischa POSLAWSKY <perl@shiar.org>
138 Licensed under the GNU Affero General Public License version 3.