use strict;
use warnings;
+use Encode;
use GetOptions;
sub convertlang($);
sub getproperties($$$$);
sub ismathfont($$);
sub correctstyle($);
+sub decimalUnicode($);
+sub contains($$);
# Following fields for a parameter can be defined:
# fieldname: Name of entry in %options
["math",
{fieldname => "Math",
comment => "Select fonts probably containing math glyphs"},],
+ ["c",
+ {fieldname => "Contains",
+ type => "=s", listsep => ',',
+ comment => "Select fonts containing all these (possibly comma separated) glyphs",}],
["l",
{fieldname => "Lang",
type => "=s", alias=>["lang"],
comment => "Comma separated list of desired languages"},],
+ ["pc",
+ {fieldname => "PrintCharset", alias => ["printcharset"],
+ comment => "Print intervals of supported unicode character values"},],
["pl",
{fieldname => "PrintLangs", alias => ["printlangs"],
comment => "Print supported languages"},],
$lg = &convertlang($lg);
}
+if (defined($options{Contains})) {
+ my %glyphs = (); # To ignore duplicates
+ for my $a1 (@{$options{Contains}}) {
+ for my $e (decimalUnicode($a1)) {
+ $glyphs{$e} = 1;
+ }
+ }
+ # create intervalls
+ my @glyphs = sort {$a <=> $b;} keys %glyphs;
+
+ # $options{Contains} no longer needed, so use it for unicode-point intervalls
+ $options{Contains} = [];
+ my ($first, $last) = (undef, undef);
+ for my $i (@glyphs) {
+ if (! defined($last)) {
+ $first = $i;
+ $last = $i;
+ next;
+ }
+ if ($i == $last+1) {
+ $last = $i;
+ next;
+ }
+ push(@{$options{Contains}}, [$first, $last]);
+ $first = $i;
+ $last = $i;
+ }
+ if (defined($last)) {
+ push(@{$options{Contains}}, [$first, $last]);
+ }
+}
+
my $cmd = "fc-list";
if (defined($langs[0])) {
$cmd .= " :lang=" . join(',', @langs);
if (exists($options{PrintLangs}) || defined($langs[0])) {
$format .= " lang=\"%{lang}\"";
}
-if (exists($options{PrintProperties}) || defined($options{Property})) {
+if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
$format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
}
+if (defined($options{Contains}) || exists($options{PrintCharset})) {
+ $format .= " charset=\"%{charset}\"";
+}
$format .= " file=\"%{file}\" abcd\\n";
$cmd .= " -f '$format'";
#print "$cmd\n";
200 => "Bold",
205 => "Extrabold",
210 => "Black",
+ 215 => "ExtraBlack",
);
my %slants = (
"o" => qr/^(octicons)/i,
"q" => qr/^(qtdingbits)/i,
"t" => qr/^(typicons|twemoji)/i,
+ "w" => qr/^(webdings)/i,
);
if (open(FI, "$cmd |")) {
$nexttype++;
}
}
- my $nfound = 0;
my %usedlangs = ();
if ($l =~ / lang=\"([^\"]+)\"/) {
my @ll = split(/\|/, $1);
for my $lang (@langs) {
next NXTLINE if (! defined($usedlangs{$lang}));
}
- next if ($nfound);
my $style = &getVal($l, "style", "stylelang");
$style =~ s/^\\040//;
my $fullname = &getVal($l, "fn", "fnl");
next NXTLINE if ($fontname !~ /$fn/i);
}
}
+ my @charlist = ();
+ if (defined($options{Contains}) || exists($options{PrintCharset})) {
+ if ($l =~ / charset=\"([^\"]+)\"/) {
+ my @list = split(/\s+/, $1);
+ for my $e (@list) {
+ my ($l, $h) = split('-', $e);
+ $h = $l if (! defined($h));
+ push(@charlist, [hex($l), hex($h)]);
+ }
+ }
+ if (defined($options{Contains})) {
+ for my $g (@{$options{Contains}}) {
+ next NXTLINE if (! contains($g, \@charlist));
+ }
+ }
+ }
my $props = "";
my @errors = ();
if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
if (exists($options{PrintLangs})) {
$props .= '(' . join(',', sort keys %usedlangs) . ')';
}
+ if (exists($options{PrintCharset})) {
+ my @out = ();
+ for my $rE (@charlist) {
+ if ($rE->[0] != $rE->[1]) {
+ push(@out, $rE->[0] . '-' . $rE->[1]);
+ }
+ else {
+ push(@out, $rE->[0]);
+ }
+ }
+ $props .= '(' . join(',', @out) . ')';
+ }
if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
my @scripts = ();
my $scripts = "";
$style =~ s/ +/ /g;
return($style);
}
+
+# return list of unicode values of the input string
+#Allow input of intervals (e.g. 'a-z')
+sub decimalUnicode($)
+{
+ my ($a) = @_;
+ my @res = ();
+ # Convert to unicode chars first
+ while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
+ my ($prev, $d, $post) = ($1, $2, $3);
+ if ($d =~ /^0?x(.+)$/) {
+ $d = hex($1);
+ }
+ my $chr = encode('utf-8', chr($d));
+ $a = $prev . $chr . $post;
+ }
+ # $a is now a string of unicode chars
+ my $u = decode('utf-8', $a);
+ my @a = split(//, $u);
+ my $interval = 0;
+ my $start = undef;
+ for my $x (@a) {
+ if ($x eq '-') { # Interval
+ $interval = 1;
+ next;
+ }
+ if ($interval && defined($start)) {
+ if (ord($x) < $start) {
+ for (my $i = $start - 1; $i >= ord($x); $i--) {
+ push(@res, $i);
+ }
+ }
+ else {
+ for (my $i = $start + 1; $i <= ord($x); $i++) {
+ push(@res, $i);
+ }
+ }
+ $start = undef;
+ }
+ else {
+ $start = ord($x);
+ push(@res, $start);
+ }
+ $interval = 0;
+ }
+ return(@res);
+}
+
+
+# check if the glyph-value $d is contained
+# in one of the (sorted) intervals
+# Inputs as intervals
+sub contains($$)
+{
+ # ok if
+ # ...re0..........re1...
+ # ......start..end......
+ my ($ri, $rList) = @_;
+ my $start = $ri->[0];
+ my $end = $ri->[1];
+
+ for my $re (@{$rList}) {
+ next if ($re->[1] < $start);
+ # now we found a possible matching interval
+ return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
+ return 0;
+ }
+ return 0;
+}