#!/usr/bin/env perl use 5.010; use strict; use warnings; use utf8; use open OUT => ':utf8', ':std'; use List::Util 'reduce'; use File::Basename 'basename'; use Data::Dump 'pp'; our $VERSION = '1.00'; my %font; my $incsuffix = '.inc.pl'; for my $fontfile (glob 'ttfsupport/*'.$incsuffix) { my ($fontid) = basename($fontfile, $incsuffix); my ($fontmeta, @fontrange) = do $fontfile or next; $font{$fontid} = { -id => $fontmeta->{id} || $fontid, -name => $fontmeta->{name}, map { (chr $_ => 1) } @fontrange }; } when (qr{^[a-z]+(?:/|\z)}) { } my %charlist; my $chartables = do 'unicode-table.inc.pl' or warn $@ || $!; if ($chartables) { while (my ($tablegroup, $grouprow) = each %{$chartables}) { while (my ($tablename, $chars) = each %{$grouprow}) { next if $tablename =~ /^-/; my $includerows; # ignore rows before body row for (@{$chars}) { $includerows ||= m/^[.]/ or next; next if /^[.-]/; next if $_ eq '>' or $_ eq '='; push @{ $charlist{table}->{"$tablegroup/$tablename"} }, $_; push @{ $charlist{table}->{$tablegroup} }, $_; } } # if ($tablegroup eq 'ipa') { # @chars = grep { !m/[a-zA-Z]/ } @chars; # } } } use Unicode::UCD 'charinfo'; for my $code (0 .. 256**2) { my $charinfo = charinfo($code) or next; next if $charinfo->{category} =~ /^[MC]/; # ignore Marks and "other" Control chars push @{ $charlist{$_}->{ $charinfo->{$_} } }, chr $code for qw( script category block ); } for (values %charlist) { for my $chars (values %{$_}) { my %row = map { my $fontcover = $font{$_}; ($_ => scalar grep { $fontcover->{$_} } @{$chars}); } keys %font; $row{-count} = scalar @{$chars}; # $row{-chars} = [ map { ord } sort @{$chars} ]; $chars = \%row; } } say 'use utf8;'; say '+'.pp(\%charlist); __END__ =head1 NAME mkfontinfo - Prepare font coverage of various character groups =head1 SYNOPSIS mkfontinfo > unicode-cover.inc.pl Test by finding the number of cyrillic characters in DejaVu Sans: perl -E'$f = do "unicode-cover.inc.pl"; say $f->{Cyrillic}->{dvsans}' =head1 AUTHOR Mischa POSLAWSKY =head1 LICENSE Licensed under the GNU Affero General Public License version 3.