2020-05-02 11:20:53 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# -*- mode: perl; -*-
|
|
|
|
|
|
|
|
# file listFontWithLang.pl
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING
|
|
|
|
# or at http://www.lyx.org/about/licence.php
|
|
|
|
#
|
|
|
|
# author Kornel Benko
|
|
|
|
# Full author contact details are available in the file CREDITS
|
|
|
|
# or at https://www.lyx.org/Credits
|
|
|
|
#
|
|
|
|
# Usage: listFontWithLang.pl <options>
|
|
|
|
# Displays installed system font names selected by <options>
|
|
|
|
# Option-strings with more that 1 char need be prefixed by '--'
|
|
|
|
#
|
|
|
|
# Option to get list of options: -h
|
2020-05-03 10:54:14 +00:00
|
|
|
#
|
2020-05-02 11:20:53 +00:00
|
|
|
# Some equivalencies for instance with option -n
|
|
|
|
# -n arial
|
|
|
|
# -N=arial
|
|
|
|
# --nAme=Arial
|
|
|
|
# --name arial
|
|
|
|
# Options and option-parameter are case insensitive
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use File::Spec;
|
|
|
|
my $p = File::Spec->rel2abs( __FILE__ );
|
|
|
|
$p =~ s/[\/\\]?[^\/\\]+$//;
|
|
|
|
unshift(@INC, $p);
|
|
|
|
}
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2020-05-18 16:21:25 +00:00
|
|
|
use Encode;
|
2020-05-02 11:20:53 +00:00
|
|
|
use GetOptions;
|
2020-06-15 08:22:10 +00:00
|
|
|
use constant {
|
|
|
|
SERIF => 1,
|
|
|
|
SANS => 2,
|
|
|
|
SCRIPT => 4,
|
|
|
|
FRAKTUR => 8,
|
|
|
|
DOUBLESTROKE => 16,
|
|
|
|
FANCY => 32,
|
|
|
|
INITIALS => 64,
|
|
|
|
SYMBOL => 128,
|
|
|
|
};
|
2020-05-02 11:20:53 +00:00
|
|
|
|
|
|
|
sub convertlang($);
|
|
|
|
sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
|
2020-05-14 15:35:51 +00:00
|
|
|
sub getIndexes($$);
|
2020-05-02 11:20:53 +00:00
|
|
|
sub getVal($$$); # my ($l, $txtval, $txtlang) = @_;
|
|
|
|
sub getproperties($$$$);
|
2020-05-09 11:19:12 +00:00
|
|
|
sub ismathfont($$);
|
2020-05-02 11:20:53 +00:00
|
|
|
sub correctstyle($);
|
2020-05-18 16:21:25 +00:00
|
|
|
sub decimalUnicode($);
|
|
|
|
sub contains($$);
|
2020-05-30 12:29:39 +00:00
|
|
|
sub sprintIntervalls($);
|
2020-05-02 11:20:53 +00:00
|
|
|
|
|
|
|
# Following fields for a parameter can be defined:
|
|
|
|
# fieldname: Name of entry in %options
|
|
|
|
# type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
|
|
|
|
# alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
|
|
|
|
# listsep: Separator for multiple data
|
|
|
|
# comment: Parameter description
|
2020-05-16 19:40:26 +00:00
|
|
|
my @optionsDef = (
|
2020-05-02 11:20:53 +00:00
|
|
|
# help + verbose already handled in 'GetOptions'
|
2020-05-16 19:40:26 +00:00
|
|
|
["n",
|
|
|
|
{fieldname => "FontName", listsep => ',',
|
|
|
|
type => "=s", alias => ["name"],
|
|
|
|
comment => "Select font-names matching these (comma separated) regexes"},],
|
|
|
|
["nn",
|
|
|
|
{fieldname => "NFontName",
|
|
|
|
type => "=s", listsep => ',',
|
|
|
|
comment => "Select font-names NOT matching these (comma separated) regexes"},],
|
|
|
|
["p",
|
|
|
|
{fieldname => "Property",
|
|
|
|
type => "=s", listsep => ',',
|
|
|
|
comment => "Select fonts with properties matching these (comma separated) regexes"},],
|
|
|
|
["np",
|
|
|
|
{fieldname => "NProperty",
|
|
|
|
type => "=s", listsep => ',',
|
|
|
|
comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
|
|
|
|
["s",
|
|
|
|
{fieldname => "Scripts",
|
|
|
|
type => "=s", listsep => ',',
|
|
|
|
comment => "Select fonts with scripts matching these (comma separated) regexes"},],
|
|
|
|
["ns",
|
|
|
|
{fieldname => "NScripts",
|
|
|
|
type => "=s", listsep => ',',
|
|
|
|
comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
|
|
|
|
["math",
|
|
|
|
{fieldname => "Math",
|
|
|
|
comment => "Select fonts probably containing math glyphs"},],
|
2020-05-18 16:21:25 +00:00
|
|
|
["c",
|
2020-05-30 12:29:39 +00:00
|
|
|
{fieldname => "Contains", alias => ["contains"],
|
2020-05-18 16:21:25 +00:00
|
|
|
type => "=s", listsep => ',',
|
2020-05-30 12:29:39 +00:00
|
|
|
comment => "Select fonts containing all these (possibly comma separated) glyphs",
|
|
|
|
comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
|
2020-06-03 18:22:19 +00:00
|
|
|
["nc",
|
|
|
|
{fieldname => "NContains",
|
|
|
|
type => "=s", listsep => ',',
|
|
|
|
comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
|
|
|
|
comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
|
2020-05-16 19:40:26 +00:00
|
|
|
["l",
|
|
|
|
{fieldname => "Lang",
|
|
|
|
type => "=s", alias=>["lang"],
|
|
|
|
comment => "Comma separated list of desired languages"},],
|
2020-05-19 06:55:41 +00:00
|
|
|
["pc",
|
|
|
|
{fieldname => "PrintCharset", alias => ["printcharset"],
|
|
|
|
comment => "Print intervals of supported unicode character values"},],
|
2020-05-16 19:40:26 +00:00
|
|
|
["pl",
|
|
|
|
{fieldname => "PrintLangs", alias => ["printlangs"],
|
|
|
|
comment => "Print supported languages"},],
|
|
|
|
["pp",
|
|
|
|
{fieldname => "PrintProperties", alias => ["printproperties"],
|
|
|
|
comment => "Print properties from weight, slant and width"},],
|
|
|
|
["ps",
|
|
|
|
{fieldname => "PrintScripts", alias => ["printscripts"],
|
|
|
|
comment => "Print supported scripts"},],
|
|
|
|
["pf",
|
|
|
|
{fieldname => "PrintFiles", alias => ["printfiles"],
|
|
|
|
comment => "Print font file names"},],
|
|
|
|
["pw",
|
|
|
|
{fieldname => "PrintWarnings",
|
|
|
|
comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
|
2020-05-02 11:20:53 +00:00
|
|
|
);
|
2020-05-16 19:40:26 +00:00
|
|
|
my %options = %{&handleOptions(\@optionsDef)};
|
2020-05-02 11:20:53 +00:00
|
|
|
|
|
|
|
$options{Lang} = "" if (! defined($options{Lang}));
|
|
|
|
|
|
|
|
#############################################################
|
|
|
|
|
|
|
|
my @langs = split(',', $options{Lang});
|
|
|
|
for my $lg (@langs) {
|
|
|
|
$lg = &convertlang($lg);
|
|
|
|
}
|
|
|
|
|
2020-06-03 18:22:19 +00:00
|
|
|
for my $charFld ("Contains", "NContains") {
|
|
|
|
if (defined($options{$charFld})) {
|
|
|
|
my %glyphs = (); # To ignore duplicates
|
|
|
|
for my $a1 (@{$options{$charFld}}) {
|
|
|
|
for my $e (decimalUnicode($a1)) {
|
|
|
|
$glyphs{$e} = 1;
|
|
|
|
}
|
2020-05-20 10:38:30 +00:00
|
|
|
}
|
2020-06-03 18:22:19 +00:00
|
|
|
# create intervalls
|
|
|
|
my @glyphs = sort {$a <=> $b;} keys %glyphs;
|
|
|
|
|
|
|
|
# $options{$charFld} no longer needed, so use it for unicode-point intervalls
|
|
|
|
$options{$charFld} = [];
|
|
|
|
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{$charFld}}, [$first, $last]);
|
2020-05-20 10:38:30 +00:00
|
|
|
$first = $i;
|
|
|
|
$last = $i;
|
|
|
|
}
|
2020-06-03 18:22:19 +00:00
|
|
|
if (defined($last)) {
|
|
|
|
push(@{$options{$charFld}}, [$first, $last]);
|
|
|
|
}
|
|
|
|
if (exists($options{verbose})) {
|
|
|
|
if ($charFld eq "Contains") {
|
|
|
|
print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
|
|
|
|
}
|
2020-05-20 10:38:30 +00:00
|
|
|
}
|
2020-05-30 12:29:39 +00:00
|
|
|
}
|
2020-05-18 16:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 11:20:53 +00:00
|
|
|
my $cmd = "fc-list";
|
|
|
|
if (defined($langs[0])) {
|
|
|
|
$cmd .= " :lang=" . join(',', @langs);
|
|
|
|
}
|
|
|
|
|
2020-05-14 15:35:51 +00:00
|
|
|
my $format = "foundry=\"%{foundry}\"" .
|
|
|
|
" postscriptname=\"%{postscriptname}\"" .
|
|
|
|
" fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
|
|
|
|
" family=\"%{family}\" flang=\"%{familylang}\" " .
|
|
|
|
" style=\"%{style}\" stylelang=\"%{stylelang}\"";
|
2020-05-02 11:20:53 +00:00
|
|
|
|
2020-06-03 18:22:19 +00:00
|
|
|
if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
|
2020-05-02 11:20:53 +00:00
|
|
|
$format .= " script=\"%{capability}\"";
|
|
|
|
}
|
|
|
|
if (exists($options{PrintLangs}) || defined($langs[0])) {
|
|
|
|
$format .= " lang=\"%{lang}\"";
|
|
|
|
}
|
2020-05-19 06:55:41 +00:00
|
|
|
if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
|
2020-05-02 11:20:53 +00:00
|
|
|
$format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
|
|
|
|
}
|
2020-06-03 18:22:19 +00:00
|
|
|
if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
|
2020-05-18 16:21:25 +00:00
|
|
|
$format .= " charset=\"%{charset}\"";
|
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
$format .= " file=\"%{file}\" abcd\\n";
|
|
|
|
$cmd .= " -f '$format'";
|
|
|
|
#print "$cmd\n";
|
|
|
|
|
2020-06-15 08:22:10 +00:00
|
|
|
|
2020-05-02 11:20:53 +00:00
|
|
|
my %ftypes = (
|
|
|
|
# Dummy internal map
|
2020-06-15 08:22:10 +00:00
|
|
|
# using '()' to prevent the initializer to take
|
|
|
|
# the key as a string. (Constants in perl _are_ functions without argument)
|
|
|
|
SERIF() => "Serif",
|
|
|
|
SANS() => "Sans",
|
|
|
|
SCRIPT() => "Script",
|
|
|
|
FRAKTUR() => "Fraktur",
|
|
|
|
DOUBLESTROKE() => "DoubleStroke",
|
|
|
|
FANCY() => "Fancy",
|
|
|
|
INITIALS() => "Initials",
|
|
|
|
SYMBOL() => "Symbol",
|
|
|
|
"default" => 1,
|
2020-05-02 11:20:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %weights = (
|
|
|
|
0 => "Thin",
|
|
|
|
40 => "Extralight",
|
|
|
|
50 => "Light",
|
|
|
|
55 => "Semilight",
|
|
|
|
75 => "Book",
|
|
|
|
80 => "Regular",
|
|
|
|
100 => "Medium",
|
|
|
|
180 => "Semibold",
|
|
|
|
200 => "Bold",
|
|
|
|
205 => "Extrabold",
|
|
|
|
210 => "Black",
|
2020-05-20 10:38:30 +00:00
|
|
|
215 => "ExtraBlack",
|
2020-05-02 11:20:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %slants = (
|
|
|
|
0 => "Roman",
|
|
|
|
100 => "Italic",
|
|
|
|
110 => "Oblique",
|
|
|
|
);
|
|
|
|
|
|
|
|
my %widths = (
|
|
|
|
50 => "Ultracondensed",
|
|
|
|
63 => "Extracondensed",
|
|
|
|
75 => "Condensed",
|
|
|
|
87 => "Semicondensed",
|
|
|
|
100 => "Normal",
|
|
|
|
113 => "Semiexpanded",
|
|
|
|
125 => "Expanded",
|
|
|
|
150 => "Extraexpanded",
|
|
|
|
200 => "Ultraexpanded",
|
|
|
|
);
|
|
|
|
|
|
|
|
my %spacings = (
|
|
|
|
0 => "Proportional",
|
|
|
|
90 => "Dual",
|
|
|
|
100 => "Mono",
|
|
|
|
110 => "Charcell",
|
|
|
|
"default" => "Proportional",
|
|
|
|
);
|
|
|
|
|
|
|
|
# Build reverse mappings, (not needed yet)
|
|
|
|
for my $txt (qw(ftypes weights slants widths spacings)) {
|
|
|
|
my $map;
|
|
|
|
eval "\$map = \\%$txt";
|
|
|
|
for my $key (keys %{$map}) {
|
|
|
|
next if ($key !~ /^\d+$/);
|
|
|
|
my $value = lc($map->{$key});
|
|
|
|
$map->{"r"}->{$value} = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# key:= fontname
|
|
|
|
# subkey foundry
|
|
|
|
# subfoundry
|
|
|
|
my %collectedfonts = ();
|
|
|
|
my %fontpriority = (
|
|
|
|
otf => 0, # type 2, opentype CFF (Compact Font Format)
|
|
|
|
ttc => 1.1, # type 1 (True Type font Collection)
|
|
|
|
ttf => 1.2, # type 1 (True Type Font)
|
|
|
|
woff=> 1.3, # type 1 (Web Open Font Format)
|
|
|
|
t1 => 1.4, # type 1 (postscript)
|
|
|
|
pfb => 1.5, # type 1 (Printer Font Binary)
|
|
|
|
pfa => 1.6, # type 1 (Printer Font Ascii)
|
2020-06-15 08:22:10 +00:00
|
|
|
pfm => 2, # requires associated .pfb file
|
2020-05-02 11:20:53 +00:00
|
|
|
pcf => 5, # Bitmap (Packaged Collaboration Files)?
|
|
|
|
);
|
|
|
|
my $nexttype = 6;
|
|
|
|
|
2020-05-12 17:53:28 +00:00
|
|
|
# list of regexes for known sans serif fonts
|
|
|
|
my %sansFonts = (
|
2020-06-15 08:22:10 +00:00
|
|
|
"value" => SANS, # Sans serif
|
2020-06-03 10:38:23 +00:00
|
|
|
"a" => qr/^(aharoni|arial|andika|angostura|anonymous|arab|aroania|arimo|asap)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"b" => qr/^b(aekmuk|ebas|erenika|eteckna|euron|lue)/i,
|
2020-06-03 18:22:19 +00:00
|
|
|
"c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|hivo|mu bright|omfortaa|omi[cx]|oolvetica|ortoba|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
|
2020-05-12 17:53:28 +00:00
|
|
|
"d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
|
|
|
|
"e" => qr/^(electron|engebrechtre)/i,
|
|
|
|
"f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
|
|
|
|
"g" => qr/^(gardiner|garuda|gfs ?neo|gillius|granada|graph|guanine|gunplay)/i,
|
|
|
|
"h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
|
|
|
|
"i" => qr/^(ibm plex|ikarius|inconsolata|induni.?h|iwona)/i,
|
|
|
|
"j" => qr/^(jara|jura)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kurier|kustom)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"m" => qr/^m(\+ |anchu|anjari|arcellus|ashq|eera|etal|igmix|igu|ikachan|intspirit|iriam ?clm|ona|onlam|ono(fonto|id|isome|noki)|ontserrat|otoyal|ukti|usica)/i,
|
2020-05-12 17:53:28 +00:00
|
|
|
"n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
|
|
|
|
"o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
|
2020-05-30 12:29:39 +00:00
|
|
|
"p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
|
2020-05-12 17:53:28 +00:00
|
|
|
"r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
|
|
|
|
"s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
|
|
|
|
"t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
|
|
|
|
"u" => qr/^(ubuntu|ukij (bom|chechek|cjk|diwani|ekran|elipbe|inchike|jelliy|kufi|qara|qolyazma|teng|title|tor)|umpush|un ?(dinaru|jamo|graphic|taza|vada|yetgul)|uni(kurd|space|versalis)|uroob|urw ?classico)/i,
|
|
|
|
"v" => qr/^(veranda|vn ?urwclassico)/i,
|
|
|
|
"w" => qr/^(waree)/i,
|
|
|
|
"y" => qr/^(yanone)/i,
|
|
|
|
"z" => qr/^(zekton|zero)/i,
|
|
|
|
);
|
2020-05-14 15:35:51 +00:00
|
|
|
my %scriptFonts = (
|
2020-06-15 08:22:10 +00:00
|
|
|
"value" => SCRIPT, # Script
|
2020-05-17 13:10:28 +00:00
|
|
|
"c" => qr/^(chancery)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"d" => qr/^(dancing)/i,
|
|
|
|
"e" => qr/^(elegante)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"j" => qr/^jsmath.?(rsfs)/i,
|
|
|
|
"k" => qr/^(kaushan|karumbi|kristi)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"m" => qr/^(mathjax_script|miama)/i,
|
|
|
|
"n" => qr/^(nanum (brush|pen) script)/i,
|
2020-05-17 13:10:28 +00:00
|
|
|
"q" => qr/^qt(arabian|boulevard|brushstroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"r" => qr/^((romande.*|ruf)script|rsfs)/i,
|
2020-05-17 13:10:28 +00:00
|
|
|
"u" => qr/^(un ?pilgi|urw ?chancery)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %fraktFonts = (
|
2020-06-15 08:22:10 +00:00
|
|
|
"value" => FRAKTUR, # Fraktur
|
2020-06-03 10:38:23 +00:00
|
|
|
"e" => qr/^eufm/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"j" => qr/^(jsmath.?euf)/i,
|
|
|
|
"m" => qr/^(missaali)/i,
|
|
|
|
"o" => qr/^(oldania)/i,
|
|
|
|
"q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london)scroll)/i,
|
|
|
|
);
|
|
|
|
|
|
|
|
my %fancyFonts = (
|
2020-06-15 08:22:10 +00:00
|
|
|
"value" => FANCY, # Fancy
|
2020-05-14 15:35:51 +00:00
|
|
|
"c" => qr/^(cretino)/i,
|
2020-06-03 18:22:19 +00:00
|
|
|
"d" => qr/^dseg/i,
|
|
|
|
"f" => qr/^frederika/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"g" => qr/^(gfs.?theo)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"k" => qr/^keter|kicking|kredit|kouzan|kerkis calligraphic/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %initialFonts = (
|
2020-06-15 08:22:10 +00:00
|
|
|
"value" => INITIALS, # Initials
|
2020-05-14 15:35:51 +00:00
|
|
|
"e" => qr/^(eb.?garamond.?init)/i,
|
|
|
|
"y" => qr/^(yinit)/i,
|
|
|
|
);
|
|
|
|
|
|
|
|
my %symbolFonts = (
|
2020-06-15 08:22:10 +00:00
|
|
|
"value" => SYMBOL, # Symbol
|
2020-05-14 15:35:51 +00:00
|
|
|
"a" => qr/^(academicons)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"c" => qr/^(caladings|ccicons|chess|cmsy|cmex)/i,
|
2020-06-03 18:22:19 +00:00
|
|
|
"d" => qr/^(dingbats|drmsym|d05)/i,
|
|
|
|
"e" => qr/^(elusiveicons|emoji|esint|euterpe)/i,
|
|
|
|
"f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
|
2020-06-11 17:10:56 +00:00
|
|
|
"g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot|complutum).?classic))/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"h" => qr/^(hots)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
|
|
|
|
"m" => qr/^(marvosym|material|msam|msbm)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"n" => qr/^(noto.*emoji)/i,
|
2020-05-17 13:10:28 +00:00
|
|
|
"o" => qr/^(octicons)/i,
|
2020-06-15 08:22:10 +00:00
|
|
|
"p" => qr/^patch/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
"q" => qr/^(qtdingbits)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"s" => qr/^stmary/i,
|
2020-05-17 13:10:28 +00:00
|
|
|
"t" => qr/^(typicons|twemoji)/i,
|
2020-06-03 10:38:23 +00:00
|
|
|
"w" => qr/^(webdings|wasy)/i,
|
2020-05-14 15:35:51 +00:00
|
|
|
);
|
|
|
|
|
2020-05-02 11:20:53 +00:00
|
|
|
if (open(FI, "$cmd |")) {
|
|
|
|
NXTLINE: while (my $l = <FI>) {
|
|
|
|
chomp($l);
|
|
|
|
while ($l !~ /abcd$/) {
|
|
|
|
$l .= <FI>;
|
|
|
|
chomp($l);
|
|
|
|
}
|
|
|
|
my $file = "";
|
|
|
|
my $fonttype;
|
|
|
|
if ($l =~ /file=\"([^\"]+)\"/) {
|
|
|
|
$file = $1;
|
|
|
|
#next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
|
|
|
|
if ($file !~ /\.([a-z0-9]{2,5})$/i) {
|
|
|
|
print "Unhandled extension for file $file\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$fonttype = lc($1);
|
|
|
|
if (! defined($fontpriority{$fonttype})) {
|
|
|
|
print "Added extension $fonttype for file $file\n";
|
|
|
|
$fontpriority{$fonttype} = $nexttype;
|
|
|
|
$nexttype++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my %usedlangs = ();
|
|
|
|
if ($l =~ / lang=\"([^\"]+)\"/) {
|
|
|
|
my @ll = split(/\|/, $1);
|
|
|
|
for my $lx (@ll) {
|
|
|
|
$usedlangs{&convertlang($lx)} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $lang (@langs) {
|
|
|
|
next NXTLINE if (! defined($usedlangs{$lang}));
|
|
|
|
}
|
|
|
|
my $style = &getVal($l, "style", "stylelang");
|
|
|
|
$style =~ s/^\\040//;
|
|
|
|
my $fullname = &getVal($l, "fn", "fnl");
|
|
|
|
my $postscriptname = "";
|
|
|
|
if ($l =~ /postscriptname=\"([^\"]+)\"/) {
|
|
|
|
$postscriptname = $1;
|
|
|
|
}
|
|
|
|
my $family = &getVal($l, "family", "flang");
|
|
|
|
$family =~ s/\\040/\-/;
|
|
|
|
my $fontname;
|
2020-05-12 17:53:28 +00:00
|
|
|
if (length($fullname) < 3) {
|
2020-05-02 11:20:53 +00:00
|
|
|
if (length($postscriptname) < 2) {
|
2020-05-12 17:53:28 +00:00
|
|
|
$fontname = "$family $style";
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$fontname = $postscriptname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-06-15 08:22:10 +00:00
|
|
|
if ($fullname !~ /^font\d+$/) {
|
|
|
|
$fontname = $fullname;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($family ne $style) {
|
|
|
|
$fontname = "$family $style";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$fontname = $family;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
if (defined($options{NFontName})) {
|
|
|
|
for my $fn (@{$options{NFontName}}) {
|
|
|
|
next NXTLINE if ($fontname =~ /$fn/i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined($options{FontName})) {
|
|
|
|
for my $fn (@{$options{FontName}}) {
|
|
|
|
next NXTLINE if ($fontname !~ /$fn/i);
|
|
|
|
}
|
|
|
|
}
|
2020-05-20 10:38:30 +00:00
|
|
|
my @charlist = ();
|
2020-06-03 18:22:19 +00:00
|
|
|
if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
|
2020-05-20 10:38:30 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2020-06-03 18:22:19 +00:00
|
|
|
if (defined($options{NContains})) {
|
|
|
|
for my $g (@{$options{NContains}}) {
|
|
|
|
# Ignore if ANY char exist in @charlist
|
|
|
|
for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
|
|
|
|
next NXTLINE if (contains([$i,$i], \@charlist));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-20 10:38:30 +00:00
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
my $props = "";
|
|
|
|
my @errors = ();
|
|
|
|
if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
|
2020-05-12 17:53:28 +00:00
|
|
|
my $properties = getproperties($l, $fontname, $style, \@errors);
|
2020-05-02 11:20:53 +00:00
|
|
|
if (defined($options{Property})) {
|
|
|
|
for my $pn (@{$options{Property}}) {
|
|
|
|
next NXTLINE if ($properties !~ /$pn/i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined($options{NProperty})) {
|
|
|
|
for my $pn (@{$options{NProperty}}) {
|
|
|
|
next NXTLINE if ($properties =~ /$pn/i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (exists($options{PrintProperties})) {
|
2020-05-08 12:17:19 +00:00
|
|
|
$props .= " ($properties)";
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists($options{PrintLangs})) {
|
|
|
|
$props .= '(' . join(',', sort keys %usedlangs) . ')';
|
|
|
|
}
|
2020-05-19 06:55:41 +00:00
|
|
|
if (exists($options{PrintCharset})) {
|
2020-05-30 12:29:39 +00:00
|
|
|
$props .= '(' . &sprintIntervalls(\@charlist) . ')';
|
2020-05-19 06:55:41 +00:00
|
|
|
}
|
2020-05-09 11:19:12 +00:00
|
|
|
if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
|
2020-05-08 12:17:19 +00:00
|
|
|
my @scripts = ();
|
|
|
|
my $scripts = "";
|
2020-05-02 11:20:53 +00:00
|
|
|
if ($l =~ / script=\"([^\"]+)\"/) {
|
2020-05-08 12:17:19 +00:00
|
|
|
@scripts = split(/\s+/, $1);
|
2020-05-02 11:20:53 +00:00
|
|
|
for my $ent (@scripts) {
|
|
|
|
$ent =~ s/^\s*otlayout://;
|
|
|
|
$ent = lc($ent);
|
|
|
|
}
|
2020-05-08 12:17:19 +00:00
|
|
|
$scripts = join(',', @scripts);
|
|
|
|
}
|
2020-05-09 11:19:12 +00:00
|
|
|
if (exists($options{Math})) {
|
2020-05-12 17:53:28 +00:00
|
|
|
next NXTLINE if (! &ismathfont($fontname,\@scripts));
|
2020-05-09 11:19:12 +00:00
|
|
|
}
|
2020-05-08 12:17:19 +00:00
|
|
|
if (exists($options{PrintScripts})) {
|
|
|
|
$props .= "($scripts)";
|
|
|
|
}
|
|
|
|
if (!defined($scripts[0])) {
|
|
|
|
# No script defined in font, so check only $options{Scripts}
|
|
|
|
next NXTLINE if (defined($options{Scripts}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (defined($options{Scripts})) {
|
|
|
|
for my $s (@{$options{Scripts}}) {
|
|
|
|
next NXTLINE if ($scripts !~ /$s/i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined($options{NScripts})) {
|
|
|
|
for my $s (@{$options{NScripts}}) {
|
|
|
|
next NXTLINE if ($scripts =~ /$s/i);
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
my $foundry = "";
|
|
|
|
if ($l =~ /foundry=\"([^\"]+)\"/) {
|
|
|
|
$foundry = $1;
|
|
|
|
$foundry =~ s/^\s+//;
|
|
|
|
$foundry =~ s/\s+$//;
|
|
|
|
}
|
|
|
|
if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
|
|
|
|
# Apparently not the first one, so add some info
|
|
|
|
my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
|
|
|
|
if (defined($errors[0])) {
|
|
|
|
push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
|
|
|
|
}
|
|
|
|
if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
|
|
|
|
push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info for file: " . $collectedfonts{$fontname}->{$foundry}->{file});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info for file: $file");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
|
|
|
|
}
|
|
|
|
$collectedfonts{$fontname}->{$foundry}->{props} = $props;
|
|
|
|
$collectedfonts{$fontname}->{$foundry}->{file} = $file;
|
|
|
|
$collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
|
|
|
|
}
|
|
|
|
close(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $fontname (sort keys %collectedfonts) {
|
|
|
|
my @foundries = sort keys %{$collectedfonts{$fontname}};
|
|
|
|
my $printfoundries = 0;
|
|
|
|
if (defined($foundries[1])) {
|
|
|
|
$printfoundries = 1;
|
|
|
|
}
|
|
|
|
for my $foundry (@foundries) {
|
|
|
|
if (exists($options{PrintWarnings})) {
|
|
|
|
for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
|
|
|
|
print "$err\n";
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 12:17:19 +00:00
|
|
|
my $fn = "Font : $fontname";
|
2020-05-02 11:20:53 +00:00
|
|
|
if ($printfoundries && ($foundry ne "")) {
|
2020-05-08 12:17:19 +00:00
|
|
|
$fn .= " \[$foundry\]";
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
2020-05-08 12:17:19 +00:00
|
|
|
print $fn;
|
2020-05-02 11:20:53 +00:00
|
|
|
print $collectedfonts{$fontname}->{$foundry}->{props};
|
|
|
|
if (exists($options{PrintFiles})) {
|
|
|
|
print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
#################################################################################
|
|
|
|
sub convertlang($)
|
|
|
|
{
|
|
|
|
my ($ilang) = @_;
|
|
|
|
if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
|
|
|
|
my ($x, $y) = ($1, $3);
|
|
|
|
if (defined($y)) {
|
|
|
|
$ilang = lc($x) . '-' . lc($y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ilang = lc($x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return($ilang);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub extractlist($$$)
|
|
|
|
{
|
|
|
|
my ($l, $islang, $txt, $rres) = @_;
|
|
|
|
my @res = ();
|
|
|
|
if ($l =~ /$txt=\"([^\"]+)\"/) {
|
2020-05-12 17:53:28 +00:00
|
|
|
@res = split(',', $1);
|
2020-05-02 11:20:53 +00:00
|
|
|
if ($islang) {
|
|
|
|
for my $lg (@res) {
|
|
|
|
$lg = &convertlang($lg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@{$rres} = @res;
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:53:28 +00:00
|
|
|
sub getIndexes($$)
|
2020-05-02 11:20:53 +00:00
|
|
|
{
|
|
|
|
my ($lang, $rlangs) = @_;
|
2020-05-12 17:53:28 +00:00
|
|
|
my @res = ();
|
|
|
|
|
2020-05-02 11:20:53 +00:00
|
|
|
for (my $i = 0; defined($rlangs->[$i]); $i++) {
|
2020-05-12 17:53:28 +00:00
|
|
|
if ($rlangs->[$i] eq $lang) {
|
|
|
|
push(@res, $i);
|
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
2020-05-12 17:53:28 +00:00
|
|
|
return(\@res);
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getVal($$$)
|
|
|
|
{
|
|
|
|
my ($l, $txtval, $txtlang) = @_;
|
|
|
|
my @values = ();
|
|
|
|
my @langs = ();
|
|
|
|
&extractlist($l, 0, $txtval, \@values);
|
|
|
|
return("") if (! defined($values[0]));
|
|
|
|
&extractlist($l, 1, $txtlang, \@langs);
|
2020-05-12 17:53:28 +00:00
|
|
|
my $i = &getIndexes("en", \@langs);
|
|
|
|
my $res = "";
|
|
|
|
for my $k (@{$i}) {
|
|
|
|
if (defined($values[$k]) && (length($values[$k]) > length($res))) {
|
|
|
|
$res = $values[$k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return($values[0]) if ($res eq "");
|
|
|
|
return($res);
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getsinglevalue($$$)
|
|
|
|
{
|
|
|
|
my ($l, $txt, $rMap, $rget) = @_;
|
|
|
|
my $val;
|
|
|
|
if ($l =~ / $txt=(\d+)/) {
|
|
|
|
$val = $1;
|
|
|
|
# Search for nearest value to $val
|
|
|
|
if (defined($rMap->{$val})) {
|
|
|
|
return($rMap->{$val});
|
|
|
|
}
|
|
|
|
my $maxv = -1;
|
|
|
|
my $minv = 1000;
|
|
|
|
for my $key (keys %{$rMap}) {
|
|
|
|
next if ($key !~ /^\d+$/);
|
|
|
|
my $diff = abs($key - $val);
|
|
|
|
if ($diff < $minv) {
|
|
|
|
$maxv = $key;
|
|
|
|
$minv = $diff;
|
|
|
|
}
|
|
|
|
elsif ($diff == $minv) {
|
2020-05-03 10:54:14 +00:00
|
|
|
if ($key < $maxv) {
|
2020-05-02 11:20:53 +00:00
|
|
|
$maxv = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! defined($rMap->{$maxv})) {
|
|
|
|
print "ERROR2: txt=$txt, val=$val\n";
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
if ($val > $maxv) {
|
|
|
|
return($rMap->{$maxv} . "+$minv");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return($rMap->{$maxv} . "-$minv");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(undef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub addTxt($$)
|
|
|
|
{
|
|
|
|
my ($txt, $val) = @_;
|
|
|
|
return("$txt($val)");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getftype($$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($fontname, $style) = @_;
|
2020-06-15 08:22:10 +00:00
|
|
|
my $resftype = 0;
|
2020-05-12 17:53:28 +00:00
|
|
|
if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SANS;
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
2020-05-12 17:53:28 +00:00
|
|
|
elsif ($fontname =~ /gothic|dotum|gulim/i) {
|
|
|
|
if ($fontname =~ /bisrat gothic/i) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SERIF;
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SANS;
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-15 08:22:10 +00:00
|
|
|
elsif ($fontname =~ /^(jsmath.?)?bbold|msbm|^(ds(rom|serif|ss))/i) {
|
|
|
|
$resftype |= DOUBLESTROKE; # Double stroke (math font)
|
2020-06-03 18:22:19 +00:00
|
|
|
}
|
2020-06-15 08:22:10 +00:00
|
|
|
if ($fontname =~ /serif|times|mincho|batang/i) {
|
2020-05-12 17:53:28 +00:00
|
|
|
if ($fontname =~ /good times/i) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SANS; # Sans Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
2020-06-15 08:22:10 +00:00
|
|
|
if ($fontname =~ /initial(s|en)/i) {
|
|
|
|
$resftype |= INITIALS;
|
|
|
|
}
|
|
|
|
if ($fontname =~ /symbol/i) {
|
|
|
|
if ($fontname !~ /^symbola/i) {
|
|
|
|
$resftype |= SYMBOL;
|
|
|
|
}
|
2020-06-11 17:10:56 +00:00
|
|
|
}
|
2020-05-12 17:53:28 +00:00
|
|
|
# Now check for fonts without a hint in font name
|
2020-06-03 10:38:23 +00:00
|
|
|
if ($fontname =~ /^([a-z])/i) {
|
2020-05-12 17:53:28 +00:00
|
|
|
my $key = lc($1);
|
2020-05-14 15:35:51 +00:00
|
|
|
for my $rFonts (\%sansFonts, \%scriptFonts, \%fraktFonts, \%fancyFonts, \%initialFonts, \%symbolFonts) {
|
|
|
|
if (defined($rFonts->{$key})) {
|
|
|
|
if ($fontname =~ $rFonts->{$key}) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= $rFonts->{"value"};
|
2020-05-14 15:35:51 +00:00
|
|
|
}
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ("$fontname" =~ /^bpg/i) {
|
|
|
|
if ("$fontname" =~ /bpg (courier gpl|elite)/i) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SERIF; # Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SANS; # Sans Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ("$fontname" =~ /^dustismo/i) {
|
|
|
|
if ("$fontname" =~ /^dustismo roman/i) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SERIF; # Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SANS; # Sans Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ("$fontname" =~ /^go\b/i) {
|
|
|
|
if ("$fontname" =~ /^go mono/i) {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SERIF; # Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-15 08:22:10 +00:00
|
|
|
$resftype |= SANS; # Sans Serif
|
2020-05-12 17:53:28 +00:00
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
2020-06-15 08:22:10 +00:00
|
|
|
# Create the string
|
|
|
|
my @ft = ();
|
|
|
|
if ($resftype == 0) {
|
|
|
|
$resftype = $ftypes{default};
|
|
|
|
}
|
|
|
|
elsif ($resftype & SANS) {
|
|
|
|
$resftype &= ~SERIF;
|
|
|
|
}
|
|
|
|
for (my $i = 1; $i < 513; $i *= 2) {
|
|
|
|
if ($resftype & $i) {
|
|
|
|
push(@ft, $ftypes{$i});
|
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
2020-06-15 08:22:10 +00:00
|
|
|
return(join(',', @ft));
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getweight($$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($fontname, $style) = @_;
|
2020-05-02 11:20:53 +00:00
|
|
|
my $result = undef;
|
2020-05-21 09:50:42 +00:00
|
|
|
for my $info ($style, $fontname) {
|
|
|
|
for my $key (keys %weights) {
|
|
|
|
next if ($key !~ /^\d+$/);
|
|
|
|
my $val = $weights{$key};
|
2020-05-02 11:20:53 +00:00
|
|
|
if ($info =~ /\b$val\b/i) {
|
2020-05-21 09:50:42 +00:00
|
|
|
return($val);
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getwidth($$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($fontname, $style) = @_;
|
2020-05-02 11:20:53 +00:00
|
|
|
my $result = undef;
|
|
|
|
for my $key (keys %widths) {
|
|
|
|
next if ($key !~ /^\d+$/);
|
2020-05-12 17:53:28 +00:00
|
|
|
for my $info ($style, $fontname) {
|
2020-05-02 11:20:53 +00:00
|
|
|
if ($info =~ /\b$widths{$key}\b/i) {
|
|
|
|
return($widths{$key});
|
|
|
|
}
|
|
|
|
if ($info =~ /\bRegular\b/) {
|
|
|
|
if (!defined($result)) {
|
|
|
|
$result = $widths{100};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getslant($$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($fontname, $style) = @_;
|
2020-05-02 11:20:53 +00:00
|
|
|
for my $key (keys %slants) {
|
|
|
|
next if ($key !~ /^\d+$/);
|
|
|
|
if ($style =~ /\b$slants{$key}\b/i) {
|
|
|
|
return($slants{$key});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(undef);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getspacing($$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($fontname, $style) = @_;
|
2020-05-02 11:20:53 +00:00
|
|
|
for my $key (keys %spacings) {
|
|
|
|
next if ($key !~ /^\d+$/);
|
|
|
|
if ($style =~ /\b$spacings{$key}\b/i) {
|
|
|
|
return($spacings{$key});
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 09:50:42 +00:00
|
|
|
if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
|
2020-05-02 11:20:53 +00:00
|
|
|
return($spacings{100}); # Mono
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(undef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 11:19:12 +00:00
|
|
|
sub ismathfont($$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($fontname, $rCapability) = @_;
|
2020-05-09 11:19:12 +00:00
|
|
|
|
2020-05-12 17:53:28 +00:00
|
|
|
return 1 if ($fontname =~ /math/i);
|
2020-05-09 11:19:12 +00:00
|
|
|
for my $cap (@{$rCapability}) {
|
|
|
|
return 1 if ($cap eq "math");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-02 11:20:53 +00:00
|
|
|
sub getproperties($$$$)
|
|
|
|
{
|
2020-05-12 17:53:28 +00:00
|
|
|
my ($l, $fontname, $style, $rerrors) = @_;
|
2020-05-02 11:20:53 +00:00
|
|
|
my $newstyle = &correctstyle($style);
|
2020-05-12 17:53:28 +00:00
|
|
|
my $newfam = &correctstyle($fontname);
|
2020-05-02 11:20:53 +00:00
|
|
|
my @properties = ();
|
|
|
|
|
|
|
|
for my $txt (qw(ftype weight width slant spacing)) {
|
|
|
|
my ($map, $rget);
|
|
|
|
eval("\$map = " . '\%' . $txt . 's');
|
|
|
|
eval('$rget = \&' . "get$txt");
|
|
|
|
my $val2 = getsinglevalue($l, $txt, $map);
|
|
|
|
my $val1 = $rget->($newfam, $newstyle);
|
|
|
|
my $val;
|
|
|
|
if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
|
2020-05-21 09:50:42 +00:00
|
|
|
if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/)){
|
|
|
|
# style overrides weight and slant
|
|
|
|
push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
|
|
|
|
$val = $val1;
|
|
|
|
}
|
|
|
|
elsif ($newfam =~ /$val1/) {
|
|
|
|
push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
|
|
|
|
$val = $val1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
|
|
|
|
$val = $val2;
|
|
|
|
}
|
2020-05-02 11:20:53 +00:00
|
|
|
}
|
|
|
|
elsif (! defined($val2)) {
|
|
|
|
$val = $val1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $val2;
|
|
|
|
}
|
|
|
|
if (defined($val)) {
|
|
|
|
push(@properties, &addTxt($txt,$val));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (defined($map->{"default"})) {
|
|
|
|
push(@properties, &addTxt($txt,$map->{"default"}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push(@{$rerrors}, "Undefined value for $txt");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(join(' ', @properties));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub correctstyle($)
|
|
|
|
{
|
|
|
|
my ($style) = @_;
|
|
|
|
$style =~ s/^\\040//;
|
|
|
|
$style =~ s/^\s*\d+\s*//;
|
|
|
|
$style =~ s/\s*\d+$//;
|
|
|
|
$style =~ s/italic/ Italic/i;
|
|
|
|
$style =~ s/oblique/ Oblique/i;
|
|
|
|
$style =~ s/[\-_]/ /g;
|
|
|
|
$style =~ s/\breg\b/Regular/i;
|
|
|
|
$style =~ s/\bregita(lic)?\b/Regular Italic/i;
|
|
|
|
$style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
|
|
|
|
$style =~ s/medium/Medium /i;
|
|
|
|
$style =~ s/\bmedita(lic)?\b/Medium Italic/i;
|
|
|
|
$style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
|
|
|
|
$style =~ s/\bmed\b/Medium /i;
|
|
|
|
$style =~ s/\bdemi\b/SemiBold/i;
|
|
|
|
$style =~ s/\bex(pd|t)\b/Expanded/i;
|
|
|
|
$style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
|
|
|
|
$style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
|
|
|
|
$style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
|
|
|
|
$style =~ s/[sd]emi ?light/SemiLight/i;
|
|
|
|
$style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
|
|
|
|
$style =~ s/light/Light /i;
|
|
|
|
$style =~ s/\blt\b/Light /i;
|
|
|
|
$style =~ s/(ultra|extra)(light|lt)/ExtraLight /i;
|
|
|
|
$style =~ s/\bheavy\b/Extrabold/i;
|
|
|
|
$style =~ s/\bhairline\b/Extralight/i;
|
|
|
|
$style =~ s/\bcond\b/Condensed/i;
|
|
|
|
$style =~ s/(roman)?slanted/ Italic/i;
|
|
|
|
$style =~ s/\bslant\b/Italic/i;
|
|
|
|
$style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
|
|
|
|
$style =~ s/w3 mono/Dual/i;
|
|
|
|
$style =~ s/Regul[ea]r/Regular/i;
|
2020-05-21 09:50:42 +00:00
|
|
|
$style =~ s/Megablack/ExtraBlack/i;
|
2020-05-02 11:20:53 +00:00
|
|
|
$style =~ s/ +/ /g;
|
|
|
|
return($style);
|
|
|
|
}
|
2020-05-18 16:21:25 +00:00
|
|
|
|
2020-05-19 06:55:41 +00:00
|
|
|
# return list of unicode values of the input string
|
2020-05-20 10:38:30 +00:00
|
|
|
#Allow input of intervals (e.g. 'a-z')
|
2020-05-18 16:21:25 +00:00
|
|
|
sub decimalUnicode($)
|
|
|
|
{
|
|
|
|
my ($a) = @_;
|
2020-05-19 06:55:41 +00:00
|
|
|
my @res = ();
|
2020-05-20 10:38:30 +00:00
|
|
|
# Convert to unicode chars first
|
|
|
|
while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
|
|
|
|
my ($prev, $d, $post) = ($1, $2, $3);
|
2020-05-19 06:55:41 +00:00
|
|
|
if ($d =~ /^0?x(.+)$/) {
|
|
|
|
$d = hex($1);
|
2020-05-18 16:21:25 +00:00
|
|
|
}
|
2020-05-20 10:38:30 +00:00
|
|
|
my $chr = encode('utf-8', chr($d));
|
|
|
|
$a = $prev . $chr . $post;
|
2020-05-19 06:55:41 +00:00
|
|
|
}
|
2020-05-20 10:38:30 +00:00
|
|
|
# $a is now a string of unicode chars
|
2020-05-19 06:55:41 +00:00
|
|
|
my $u = decode('utf-8', $a);
|
|
|
|
my @a = split(//, $u);
|
2020-05-20 10:38:30 +00:00
|
|
|
my $interval = 0;
|
|
|
|
my $start = undef;
|
2020-05-19 06:55:41 +00:00
|
|
|
for my $x (@a) {
|
2020-05-20 10:38:30 +00:00
|
|
|
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;
|
2020-05-18 16:21:25 +00:00
|
|
|
}
|
2020-05-19 06:55:41 +00:00
|
|
|
return(@res);
|
2020-05-18 16:21:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 10:38:30 +00:00
|
|
|
|
2020-05-21 09:50:42 +00:00
|
|
|
# check if the glyph-values in interval @{$ri} are contained
|
2020-05-19 06:55:41 +00:00
|
|
|
# in one of the (sorted) intervals
|
2020-05-18 16:21:25 +00:00
|
|
|
sub contains($$)
|
|
|
|
{
|
2020-05-20 10:38:30 +00:00
|
|
|
# ok if
|
|
|
|
# ...re0..........re1...
|
|
|
|
# ......start..end......
|
|
|
|
my ($ri, $rList) = @_;
|
|
|
|
my $start = $ri->[0];
|
|
|
|
my $end = $ri->[1];
|
|
|
|
|
2020-05-18 16:21:25 +00:00
|
|
|
for my $re (@{$rList}) {
|
2020-05-20 10:38:30 +00:00
|
|
|
next if ($re->[1] < $start);
|
|
|
|
# now we found a possible matching interval
|
|
|
|
return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
|
|
|
|
return 0;
|
2020-05-18 16:21:25 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-30 12:29:39 +00:00
|
|
|
|
|
|
|
sub sprintIntervalls($)
|
|
|
|
{
|
|
|
|
my ($rList) = @_;
|
|
|
|
my @out = ();
|
|
|
|
for my $rE (@{$rList}) {
|
|
|
|
if ($rE->[0] != $rE->[1]) {
|
|
|
|
push(@out, $rE->[0] . '-' . $rE->[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push(@out, $rE->[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return join(',', @out);
|
|
|
|
}
|