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 my $year = substr $fontmeta->{date}, 0, 4;
22 $fontmeta->{description} = join(' ',
23 (map { "version $_" } $fontmeta->{version} || ()),
24 $fontmeta->{version} && $fontmeta->{version} =~ /\Q$year/ ? () :
25 (map { "($_)" } $year || ()),
27 push @fontlist, $fontmeta;
28 $cover{$fontid} = { map { (chr $_ => 1) } @fontrange };
33 my $chartables = do 'unicode-table.inc.pl' or warn $@ || $!;
35 while (my ($tablegroup, $grouprow) = each %{$chartables}) {
36 while (my ($tablename, $chars) = each %{$grouprow}) {
37 next if $tablename =~ /^-/;
38 my $includerows; # ignore rows before body row
40 $includerows ||= m/^[.]/ or next;
42 next if $_ eq '>' or $_ eq '=';
44 length $_ == 1 or next; # multiple characters lost in query
45 push @{ $charlist{table}->{"$tablegroup/$tablename"} }, $_;
46 push @{ $charlist{table}->{$tablegroup} }, $_;
49 # if ($tablegroup eq 'ipa') {
50 # @chars = grep { !m/[a-zA-Z]/ } @chars;
56 require HTML::Entities;
58 HTML::Entities->import('%char2entity');
59 while (my ($char, $entity) = each %char2entity) {
60 $entity =~ /[a-zA-Z]/ or next; # only actual aliases
61 push @{ $charlist{table}->{html} }, $char;
64 } or warn "Could not include count for html entities: $@";
67 use Unicode::UCD 'charinfo';
68 for my $code (0 .. 256**2*2) {
69 my $charinfo = charinfo($code) or next;
70 next if $charinfo->{category} =~ /^[MC]/; # ignore Marks and "other" Control chars
71 push @{ $charlist{$_}->{ $charinfo->{$_} } }, chr $code
72 for qw( script category block );
75 } or warn "Could not include unicode groups: $@";
77 for (values %charlist) {
78 for my $chars (values %{$_}) {
81 map { scalar grep { defined } @{ $cover{$_->{file}} }{ @{$chars} } }
84 $row{count} = scalar @{$chars};
87 my @query = map { ord } sort @{$chars};
94 last if $query[$j] != $v;
98 splice(@query, $i, $j - $i, "$query[$i]-$query[$j-1]");
102 return join '+', @query;
109 $charlist{fonts} = \@fontlist;
112 win95 => [qw( arial.win95 arialuni lucidau verdana.win95 times.win95 cour.win95 )], # microsoft
113 win7 => [qw( arial.win7 verdana.win7 times.win7 cour.win7 )],
114 win8 => [qw( arial.win8 verdana.win8 times.win8 cour.win8 )],
115 mac10 => [qw( helvetica.mac10 lucida.mac10 times.mac10 garamond.mac10 palatino.mac10 lucida.mac10 )], # apple
116 android => [qw( roboto notosans )], # google
117 oss => [qw( dvsans code2000 unifont opensans )],
119 my %fontnum = map { ($fontlist[$_]->{file} => $_) } 0 .. $#fontlist;
120 while (my ($os, $fontids) = each %osfonts) {
121 $charlist{os}->{$os} = [ map { $fontnum{$_} // () } @{$fontids} ];
123 $charlist{osdefault} = [qw( win95 win8 mac10 oss android )];
125 say "# automatically generated by $0";
127 say '+', pp(\%charlist) =~ s{
128 ( \[ \s* \d [^]]* ) ,\s* # arrays of numbers, excluding trailing comma
129 }{ $1 =~ s/\s+//gr }msxgre; # strip whitespace
135 mkfontinfo - Prepare font coverage of various character groups
139 mkfontinfo > unicode-cover.inc.pl
141 Test by finding the number of cyrillic characters in DejaVu Sans:
143 perl -E'$f = do "unicode-cover.inc.pl"; say $f->{Cyrillic}->{dvsans}'
147 Mischa POSLAWSKY <perl@shiar.org>
151 Licensed under the GNU Affero General Public License version 3.