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 push @{ $charlist{table}->{"$tablegroup/$tablename"} }, $_;
39 push @{ $charlist{table}->{$tablegroup} }, $_;
42 # if ($tablegroup eq 'ipa') {
43 # @chars = grep { !m/[a-zA-Z]/ } @chars;
49 require HTML::Entities;
51 HTML::Entities->import('%char2entity');
52 while (my ($char, $entity) = each %char2entity) {
53 $entity =~ /[a-zA-Z]/ or next; # only actual aliases
54 push @{ $charlist{table}->{html} }, $char;
57 } or warn "Could not include count for html entities: $@";
59 use Unicode::UCD 'charinfo';
60 for my $code (0 .. 256**2) {
61 my $charinfo = charinfo($code) or next;
62 next if $charinfo->{category} =~ /^[MC]/; # ignore Marks and "other" Control chars
63 push @{ $charlist{$_}->{ $charinfo->{$_} } }, chr $code
64 for qw( script category block );
67 for (values %charlist) {
68 for my $chars (values %{$_}) {
71 map { scalar grep { defined } @{ $cover{$_->{file}} }{ @{$chars} } }
74 $row{count} = scalar @{$chars};
77 my @query = map { ord } sort @{$chars};
84 last if $query[$j] != $v;
88 splice(@query, $i, $j - $i, "$query[$i]-$query[$j-1]");
92 return join '+', @query;
99 $charlist{fonts} = \@fontlist;
102 win95 => [qw( arial arialuni lucidau verdana timesnew couriernew )], # microsoft
103 mac10 => [qw( helvetica lucida times garamond palatino )], # apple
104 android => [qw( roboto noto )], # google
105 oss => [qw( dvsans c2k unifont opensans )],
107 my %fontnum = map { ($fontlist[$_]->{file} => $_) } 0 .. $#fontlist;
108 while (my ($os, $fontids) = each %osfonts) {
109 $charlist{os}->{$os} = [ map { $fontnum{$_} // () } @{$fontids} ];
111 $charlist{osdefault} = [qw( win95 mac10 oss android )];
113 say "# automatically generated by $0";
115 say '+'.pp(\%charlist);
121 mkfontinfo - Prepare font coverage of various character groups
125 mkfontinfo > unicode-cover.inc.pl
127 Test by finding the number of cyrillic characters in DejaVu Sans:
129 perl -E'$f = do "unicode-cover.inc.pl"; say $f->{Cyrillic}->{dvsans}'
133 Mischa POSLAWSKY <perl@shiar.org>
137 Licensed under the GNU Affero General Public License version 3.