6 use open OUT => ':utf8', ':std';
7 use File::Basename 'basename';
10 our $VERSION = '1.01';
15 my $incsuffix = '.inc.pl';
16 for my $fontfile (glob 'data/font/*'.$incsuffix) {
17 my ($fontid) = basename($fontfile, $incsuffix);
18 my ($fontmeta, @fontrange) = do "./$fontfile";
23 $fontmeta->{file} = $fontid;
24 my $year = substr $fontmeta->{date}, 0, 4;
25 $fontmeta->{description} = join(' ',
26 (map { "version $_" } $fontmeta->{version} || ()),
27 $fontmeta->{version} && $fontmeta->{version} =~ /\Q$year/ ? () :
28 (map { "($_)" } $year || ()),
30 push @fontlist, $fontmeta;
31 $cover{$fontid} = { map { (chr $_ => 1) } @fontrange };
36 $charlist{table}->{abc} = ['A'..'Z', 'a'..'z'];
38 my $chartables = do './unicode-table.inc.pl' or warn $@ || $!;
40 while (my ($tablegroup, $grouprow) = each %{$chartables}) {
41 while (my ($tablename, $chars) = each %{$grouprow}) {
42 next if $tablename =~ /^-/;
43 my $includerows; # ignore rows before body row
45 $includerows ||= m/^[.]/ or next;
47 next if $_ eq '>' or $_ eq '=';
49 length $_ == 1 or next; # multiple characters lost in query
50 push @{ $charlist{table}->{"$tablegroup/$tablename"} }, $_;
51 push @{ $charlist{table}->{$tablegroup} }, $_;
54 # if ($tablegroup eq 'ipa') {
55 # @chars = grep { !m/[a-zA-Z]/ } @chars;
61 require HTML::Entities;
63 HTML::Entities->import('%char2entity');
64 while (my ($char, $entity) = each %char2entity) {
65 $entity =~ /[a-zA-Z]/ or next; # only actual aliases
66 push @{ $charlist{table}->{html} }, $char;
69 } or warn "Could not include count for html entities: $@";
72 my $agemap = do './data/unicode-age.inc.pl'
73 or warn "Could not include unicode version data: $!";
75 use Unicode::UCD 'charinfo';
76 for my $code (0 .. 256**2*2) {
77 my $charinfo = charinfo($code) or next;
78 next if $charinfo->{category} =~ /^[MC]/; # ignore Marks and "other" Control chars
79 push @{ $charlist{$_}->{ $charinfo->{$_} } }, chr $code
80 for qw( script category block );
81 push @{ $charlist{version}->{$_} }, (chr $code) x ($agemap->{$code} <= $_)
85 } or warn "Could not include unicode groups: $@";
87 for (values %charlist) {
88 for my $chars (values %{$_}) {
91 map { scalar grep { defined } @{ $cover{$_->{file}} }{ @{$chars} } }
94 $row{count} = scalar @{$chars};
97 my @query = map { ord } sort @{$chars};
102 while ($j < @query) {
104 last if $query[$j] != $v;
108 splice(@query, $i, $j - $i, "$query[$i]-$query[$j-1]");
112 return join '+', @query;
119 $charlist{fonts} = \@fontlist;
122 win2k => [qw( arial.win2k arialuni lucidau verdana.win2k times.win2k cour.win2k )], # microsoft
123 win8 => [map {"$_.win8"} qw( arial verdana times georgia pala cour )],
124 mac109 => [map {"$_.mac109"} qw( helv lucida times pala )], # apple
125 android => [qw( roboto droidmono notosans )], # google
126 oss => [qw( dvsans freesans code2000 unifont )],
129 # copy rows to derive older os versions (same list with different trailing number)
130 s/8$/7/ for @{ $osfonts{ win7} = [@{ $osfonts{ win8} }] };
131 s/9$/7/ for @{ $osfonts{mac107} = [@{ $osfonts{mac109} }] };
134 my %fontnum = map { ($fontlist[$_]->{file} => $_) } 0 .. $#fontlist;
135 while (my ($os, $fontids) = each %osfonts) {
136 $charlist{os}->{$os} = [ map { $fontnum{$_} // () } @{$fontids} ];
138 $charlist{osdefault} = [qw( win2k win8 mac109 android oss )];
140 say "# automatically generated by $0";
142 say '+', pp(\%charlist) =~ s{
143 ( \[ \s* \d [^]]* ) ,\s* (?= \] ) # arrays of numbers, excluding trailing comma
144 }{ $1 =~ s/\s+//gr }msxgre; # strip whitespace
150 mkfontinfo - Prepare font coverage of various character groups
154 mkfontinfo > unicode-cover.inc.pl
156 Test by finding the number of cyrillic characters in DejaVu Sans:
158 perl -E'$f = do "unicode-cover.inc.pl"; say $f->{Cyrillic}->{dvsans}'
162 Mischa POSLAWSKY <perl@shiar.org>
166 Licensed under the GNU Affero General Public License version 3.