4 # file listFontWithLang.pl
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING
7 # or at http://www.lyx.org/about/licence.php
10 # Full author contact details are available in the file CREDITS
11 # or at https://www.lyx.org/Credits
13 # Usage: listFontWithLang.pl <options>
14 # Displays installed system font names selected by <options>
15 # Option-strings with more that 1 char need be prefixed by '--'
17 # Option to get list of options: -h
19 # Some equivalencies for instance with option -n
24 # Options and option-parameter are case insensitive
28 my $p = File::Spec->rel2abs( __FILE__ );
29 $p =~ s/[\/\\]?[^\/\\]+$//;
49 # for UseProperty (UP)
50 UPPROPERTY => 1, # select
51 UPNPROPERTY => 2, # deselect
52 UPPPROPERTIES => 4, # print
53 UPWPROPERTIES => 8, # write to a file
55 # for UseCharsets (UC)
56 UCCONTAINS => 1, # select
57 UCNCONTAINS => 2, # deselect
58 UCPCONTAINS => 4, # print
61 USSCRIPT => 1, # select
62 USNSCRIPT => 2, # deselect
63 USMSCRIPT => 4, # math
64 USPSCRIPT => 8, # print
65 USWSCRIPT => 16, # write to a file
68 # These will be set according to options
69 my $iproperty = 0; # info for Use Properties
70 my $icontains = 0; # info for Use Charsets
71 my $iscript = 0; # info for Use Scripts
74 sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
76 sub getVal($$$$); # my ($l, $txtval, $txtlang, $combine) = @_;
77 sub getproperties($$$$);
80 sub decimalUnicode($);
82 sub sprintIntervalls($);
83 sub buildFontName($$);
84 sub splitatlU($); # split text at change from lower case to upper case
87 # Following fields for a parameter can be defined:
88 # fieldname: Name of entry in %options
89 # type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
90 # alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
91 # listsep: Separator for multiple data
92 # comment: Parameter description
94 # help + verbose already handled in 'GetOptions'
96 {fieldname => "FontName", listsep => ',',
97 type => "=s", alias => ["name"],
98 comment => "Select font-names matching these (comma separated) regexes"},],
100 {fieldname => "NFontName",
101 type => "=s", listsep => ',',
102 comment => "Select font-names NOT matching these (comma separated) regexes"},],
104 {fieldname => "Property",
105 type => "=s", listsep => ',',
106 comment => "Select fonts with properties matching these (comma separated) regexes"},],
108 {fieldname => "NProperty",
109 type => "=s", listsep => ',',
110 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
112 {fieldname => "Scripts",
113 type => "=s", listsep => ',',
114 comment => "Select fonts with scripts matching these (comma separated) regexes"},],
116 {fieldname => "NScripts",
117 type => "=s", listsep => ',',
118 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
120 {fieldname => "Math",
121 comment => "Select fonts probably containing math glyphs"},],
123 {fieldname => "Contains", alias => ["contains"],
124 type => "=s", listsep => ',',
125 comment => "Select fonts containing all these (possibly comma separated) glyphs",
126 comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
128 {fieldname => "NContains",
129 type => "=s", listsep => ',',
130 comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
131 comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
133 {fieldname => "Lang",
134 type => "=s", alias=>["lang"],
135 comment => "Comma separated list of desired languages"},],
137 {fieldname => "PrintCharset", alias => ["printcharset"],
138 comment => "Print intervals of supported unicode character values"},],
140 {fieldname => "PrintLangs", alias => ["printlangs"],
141 comment => "Print supported languages"},],
143 {fieldname => "PrintProperties", alias => ["printproperties"],
144 comment => "Print properties from weight, slant and width"},],
146 {fieldname => "PrintScripts", alias => ["printscripts"],
147 comment => "Print supported scripts"},],
149 {fieldname => "PrintFiles", alias => ["printfiles"],
150 comment => "Print font file names"},],
152 {fieldname => "PrintWarnings",
153 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
155 {fieldname => "Write",
156 type => "=s", alias => ["writefile"],
157 comment => "Write to a file for later use"},],
159 my %options = %{&handleOptions(\@optionsDef)};
161 $options{Lang} = "" if (! defined($options{Lang}));
163 #############################################################
165 "Cond" => "Condensed",
166 "Expd" => "Expanded",
173 my @langs = split(',', $options{Lang});
174 for my $lg (@langs) {
175 $lg = &convertlang($lg);
178 $iproperty |= UPPROPERTY if (defined($options{Property}));
179 $iproperty |= UPNPROPERTY if (defined($options{NProperty}));
180 $iproperty |= UPPPROPERTIES if (exists($options{PrintProperties}));
182 $icontains |= UCCONTAINS if (defined($options{Contains}));
183 $icontains |= UCNCONTAINS if (defined($options{NContains}));
184 $icontains |= UCPCONTAINS if (exists($options{PrintCharset}));
186 $iscript |= USSCRIPT if (defined($options{Scripts}));
187 $iscript |= USNSCRIPT if (defined($options{NScripts}));
188 $iscript |= USMSCRIPT if (exists($options{Math}));
189 $iscript |= USPSCRIPT if (exists($options{PrintScripts}));
191 if (defined($options{Write})) {
192 if (! open(INFOS, '>', $options{Write})) {
193 die("Could not open file $options{Write} for write");
195 $iproperty |= UPWPROPERTIES;
197 # $iscript |= USWSCRIPT;
200 for my $charFld ("Contains", "NContains") {
201 if (defined($options{$charFld})) {
202 my %glyphs = (); # To ignore duplicates
203 for my $a1 (@{$options{$charFld}}) {
204 for my $e (decimalUnicode($a1)) {
209 my @glyphs = sort {$a <=> $b;} keys %glyphs;
211 # $options{$charFld} no longer needed, so use it for unicode-point intervalls
212 $options{$charFld} = [];
213 my ($first, $last) = (undef, undef);
214 for my $i (@glyphs) {
215 if (! defined($last)) {
224 push(@{$options{$charFld}}, [$first, $last]);
228 if (defined($last)) {
229 push(@{$options{$charFld}}, [$first, $last]);
231 if (exists($options{verbose})) {
232 if ($charFld eq "Contains") {
233 print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
236 print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
242 for my $fn ("FontName", "NFontName") {
243 if (defined($options{$fn})) {
244 # split each entry and make a compiled regex
245 # Allow space between all characters
246 for my $e (@{$options{$fn}}) {
247 my $u = decode('utf-8', $e);
248 my $fill = decode('utf-8', "\\s?");
249 my @u = split(//, $u);
252 push(@ud, $c, $fill);
254 my $ud = join('', @ud);
255 my $e1 = encode('utf-8', $ud);
263 if (defined($langs[0])) {
264 $cmd .= " :lang=" . join(',', @langs);
267 my $format = "foundry=\"%{foundry}\"" .
268 " postscriptname=\"%{postscriptname}\"" .
269 " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
270 " family=\"%{family}\" flang=\"%{familylang}\" " .
271 " style=\"%{style}\" stylelang=\"%{stylelang}\"";
274 $format .= " script=\"%{capability}\"";
276 if (exists($options{PrintLangs}) || defined($langs[0])) {
277 $format .= " lang=\"%{lang}\"";
280 $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
283 $format .= " charset=\"%{charset}\"";
285 $format .= " file=\"%{file}\" abcd\\n";
286 $cmd .= " -f '$format'";
292 # using '()' to prevent the initializer to take
293 # the key as a string. (Constants in perl _are_ functions without argument)
296 SCRIPT() => "Script",
297 FRAKTUR() => "Fraktur",
298 DOUBLESTROKE() => "DoubleStroke",
300 INITIALS() => "Initials",
301 SYMBOL() => "Symbol",
302 SMALLCAP() => "SmallCap",
328 50 => "Ultracondensed",
329 63 => "Extracondensed",
331 87 => "Semicondensed",
333 113 => "Semiexpanded",
335 150 => "Extraexpanded",
336 200 => "Ultraexpanded",
344 "default" => "Proportional",
347 # Build reverse mappings, (not needed yet)
348 for my $txt (qw(ftypes weights slants widths spacings)) {
350 eval "\$map = \\%$txt";
351 for my $key (keys %{$map}) {
352 next if ($key !~ /^\d+$/);
353 my $value = lc($map->{$key});
354 $map->{"r"}->{$value} = $key;
361 my %collectedfonts = ();
363 otf => 0, # type 2, opentype CFF (Compact Font Format)
364 ttc => 1.1, # type 1 (True Type font Collection)
365 ttf => 1.2, # type 1 (True Type Font)
366 woff=> 1.3, # type 1 (Web Open Font Format)
367 t1 => 1.4, # type 1 (postscript)
368 pfb => 1.5, # type 1 (Printer Font Binary)
369 pfa => 1.6, # type 1 (Printer Font Ascii)
370 pfm => 2, # requires associated .pfb file
371 pcf => 5, # Bitmap (Packaged Collaboration Files)?
376 # some extra serif fonts
378 "g" => qr/^gfs ?(didot)/i,
380 # list of regexes for known sans serif fonts
382 "value" => SANS, # Sans serif
383 "a" => qr/^a(030|bydos|haroni|e?rial|ndika|ngostura|nonymous|rab|roania|rimo|rundina|sap|e almothnna|egean|egyptus|l (arabiya|battar|hor|manzomah|yarmook)|lmonte|natolian|ndale|nglepoise|njali|xaxa)/i,
384 "b" => qr/^b(abel ?stone ?modern|aekmuk|alker|altar|andal|angwool|arbatrick|aveuse|old|dxsfm|ebas|erenika|eteckna|euron|iometric|iting|lue|m ?hanna)/i,
385 "c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|harles|hilanka|hinese ?rocks|hivo|mu bright|omfortaa|omi[cx]|omputer ?(bold|(modern ?(bright ?((semi)?bold|math|oblique|roman|italic))))|oolvetica|ortoba|ountries|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
386 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
387 "e" => qr/^(electron|engebrechtre)/i,
388 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
389 "g" => qr/^g(ardiner|aruda|fs ?neo|illius|ood ?times|ranada|raph|uanine|unplay)/i,
390 "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
391 "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
392 "j" => qr/^j(ara|ura|s ?math.?bbold)/i,
393 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kp ?mono|kurier|kustom)/i,
394 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation ?mono|ibre franklin|ibris|inux biolinum|obster|ogix|ohit ?(devana|telugu)|oma)/i,
395 "m" => qr/^m(\+ |anchu|anjari|arcellus|ashq|eera|etal|igmix|igu|ikachan|intspirit|iriam ?clm|isaki|itra ?mono|ona|onlam|ono(fonto|id|isome|noki)|ontserrat|otoyal|ukti|usica)/i,
396 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice|noto ?mono)/i,
397 "o" => qr/^(ocr|okolaks|open ?dyslexic|ostorah|ouhud|over|oxygen)/i,
398 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
399 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
400 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
401 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
402 "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
403 "u" => qr/^u(buntu|kij (bom|chechek|cjk|diwani|ekran|elipbe|inchike|jelliy|kufi|mejnuntal|qara|qolyazma|teng|title|tor|tuz ?(neqish|tom))|mpush|n ?(dinaru|jamo|graphic|taza|vada|yetgul)|ni(kurd|space|versalis)|roob|rw ?classico)/i,
404 "v" => qr/^(veranda|vn ?urwclassico)/i,
405 "w" => qr/^(waree)/i,
406 "y" => qr/^(yanone)/i,
407 "z" => qr/^(zekton|zero)/i,
410 "value" => SCRIPT, # Script
411 "a" => qr/^a(becedario|ir ?cut|ugie|uriocus ?kalligraph)/i,
412 "b" => qr/^b(reip|rush ?script)/i,
413 "c" => qr/^(chancery)/i,
414 "d" => qr/^(dancing)/i,
415 "e" => qr/^(elegante)/i,
416 "f" => qr/^femkeklaver/i,
417 "j" => qr/^jsmath.?(rsfs)/i,
418 "k" => qr/^(kaushan|karumbi|kristi)/i,
419 "m" => qr/^(math ?jax.?script|miama)/i,
420 "n" => qr/^(nanum (brush|pen) script)/i,
422 "q" => qr/^qt( ?black ?forest|arabian|boulevard|brush ?stroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
423 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
424 "t" => qr/^typo ?script/i,
425 "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
429 "value" => FRAKTUR, # Fraktur
430 "b" => qr/^boondox ?fraktur/i,
432 "j" => qr/^(jsmath.?euf)/i,
433 "m" => qr/^(missaali)/i,
434 "o" => qr/^(oldania)/i,
435 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london) ?scroll)/i,
436 "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
440 "value" => FANCY, # Fancy
441 "a" => qr/^a(bandoned|bberancy|driator|irmole|lmendra ?display|lmonte (snow|woodgrain)|nalecta|ni|nklepants|nn ?stone|oyagi|rt ?nouveau ?caps|stron|xaxa)/i,
442 "b" => qr/^b(aileys|alcony|altar|andal|arbatrick|aveuse|eat ?my|etsy|iometric|iting|lankenburg|oondox ?callig|org|oron|raeside|ramalea|udmo|urnstown|utterbelly)/i,
443 "c" => qr/^c(retino|msy|abin ?sketch|arbon|arolingan|harles|hicken|hilanka|hr\d)/i,
445 "e" => qr/^electorate/i,
446 "f" => qr/^frederika/i,
447 "g" => qr/^(gfs.?theo)/i,
448 "j" => qr/^jsmath.cmsy/i,
449 "k" => qr/^keter|kicking|kredit|kouzan/i,
451 "q" => qr/^qtcaslan ?open/i,
452 "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
453 "v" => qr/^vectroid/i,
457 "value" => INITIALS, # Initials
458 "c" => qr/^carrick/i,
459 "e" => qr/^(eb.?garamond.?init)/i,
460 "t" => qr/^typographer/i,
461 "y" => qr/^(yinit)/i,
465 "value" => SYMBOL, # Symbol
466 "a" => qr/^a(cademicons|lblant|lianna|mar|nka|rb?\d|rchaic|rrow|rs|rt[mt]|ssy(rb\d+)?\b|miri ?quran|mit\b)/i,
467 "b" => qr/^b(aby ?jeepers|bding|euron|guq|lex|lsy|oondox ?upr|ullets|urma)/i,
468 "c" => qr/^c(aladings|cicons|hess|msy|mex|apacitor|ounterscraps)/i,
469 "d" => qr/^(dingbats|drmsym|d05)/i,
470 "e" => qr/^e(lusiveicons|mmentaler|moji|sint|uterpe)/i,
471 "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
472 "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot).?classic|complutum))/i,
473 "h" => qr/^h(ots|ershey)/i,
474 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
475 "l" => qr/^l(cmsy|msam|ohit ?(Assamese|Bengali|Gujarati|Gurmukhi|Kannada|Malayalam|Marathi|Nepali|Odia|Tamil))/i,
476 "m" => qr/^(marvosym|material|msam|msbm)/i,
477 "n" => qr/^(noto.*(emoji|brahmi))/i,
478 "o" => qr/^(octicons)/i,
480 "q" => qr/^(qtding ?bits)/i,
481 "s" => qr/^s(emafor|kak|tmary|s?msam|tix ?math)/i,
482 "t" => qr/^(te ?xxslh?[du]|typicons|twemoji)/i,
483 "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
484 "w" => qr/^w(ebdings|asy|elfare ?brat)/i,
487 my %smallcapFonts = (
488 "value" => SMALLCAP | SERIF,
489 "c" => qr/^c(s[ct]sc\d|inzel|omputer ?modern ?sans ?italic ?regular ?\d)/i,
490 "d" => qr/^drm(it)?sc\d/i,
491 "f" => qr/^fetamont.?script/i,
492 "n" => qr/^newtxb?ttsc/i,
493 "s" => qr/^(screengem|sf.?kp.?sc)/i,
494 "t" => qr/^t1?xb?ttsc/i,
495 "v" => qr/^vn ?cccsc\d/i,
498 if (open(FI, "$cmd |")) {
499 NXTLINE: while (my $l = <FI>) {
501 while ($l !~ /abcd$/) {
507 if ($l =~ /file=\"([^\"]+)\"/) {
509 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
510 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
511 print "Unhandled extension for file $file\n";
515 if (! defined($fontpriority{$fonttype})) {
516 print "Added extension $fonttype for file $file\n";
517 $fontpriority{$fonttype} = $nexttype;
522 if ($l =~ / lang=\"([^\"]+)\"/) {
523 my @ll = split(/\|/, $1);
525 $usedlangs{&convertlang($lx)} = 1;
529 for my $lang (@langs) {
530 next NXTLINE if (! defined($usedlangs{$lang}));
532 my ($fullname, $fuidx) = &getVal($l, "fn", "fnl", -1);
533 my ($style, $fsidx) = &getVal($l, "style", "stylelang", $fuidx);
534 $style =~ s/^\\040//;
535 my ($family, $faidx) = &getVal($l, "family", "flang", $fsidx);
537 my $postscriptname = "";
538 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
539 $postscriptname = $1;
542 ($fontname, $style) = &buildFontName($family, $style);
543 if (defined($options{NFontName})) {
544 for my $fn (@{$options{NFontName}}) {
545 next NXTLINE if ($fontname =~ $fn);
548 if (defined($options{FontName})) {
549 for my $fn (@{$options{FontName}}) {
550 next NXTLINE if ($fontname !~ $fn);
555 if ($l =~ / charset=\"([^\"]+)\"/) {
556 my @list = split(/\s+/, $1);
558 my ($l, $h) = split('-', $e);
559 $h = $l if (! defined($h));
560 push(@charlist, [hex($l), hex($h)]);
563 if ($icontains & UCCONTAINS) {
564 for my $g (@{$options{Contains}}) {
565 next NXTLINE if (! contains($g, \@charlist));
568 if ($icontains & UCNCONTAINS) {
569 for my $g (@{$options{NContains}}) {
570 # Ignore if ANY char exist in @charlist
571 for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
572 next NXTLINE if (contains([$i,$i], \@charlist));
581 my $properties = getproperties($l, $fontname, $style, \@errors);
582 if ($iproperty & UPPROPERTY) {
583 for my $pn (@{$options{Property}}) {
584 next NXTLINE if ($properties !~ /$pn/i);
587 if ($iproperty & UPNPROPERTY) {
588 for my $pn (@{$options{NProperty}}) {
589 next NXTLINE if ($properties =~ /$pn/i);
592 if ($iproperty & UPPPROPERTIES) {
593 $props .= " ($properties)";
595 if ($iproperty & UPWPROPERTIES) {
596 $wprops .= " ($properties)";
599 if (exists($options{PrintLangs})) {
600 $props .= '(' . join(',', sort keys %usedlangs) . ')';
602 if (exists($options{PrintCharset})) {
603 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
608 if ($l =~ / script=\"([^\"]+)\"/) {
609 @scripts = split(/\s+/, $1);
610 for my $ent (@scripts) {
611 $ent =~ s/^\s*otlayout://;
614 $scripts = join(',', @scripts);
616 if ($iscript & USMSCRIPT) {
617 next NXTLINE if (! &ismathfont($fontname,\@scripts));
619 if ($iscript & USPSCRIPT) {
620 $props .= "($scripts)";
622 if (!defined($scripts[0])) {
623 # No script defined in font, so check only $options{Scripts}
624 next NXTLINE if ($iscript & USSCRIPT);
627 if ($iscript & USSCRIPT) {
628 for my $s (@{$options{Scripts}}) {
629 next NXTLINE if ($scripts !~ /$s/i);
632 if ($iscript & USNSCRIPT) {
633 for my $s (@{$options{NScripts}}) {
634 next NXTLINE if ($scripts =~ /$s/i);
640 if ($l =~ /foundry=\"([^\"]+)\"/) {
642 $foundry =~ s/^\s+//;
643 $foundry =~ s/\s+$//;
645 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
646 # Apparently not the first one, so add some info
647 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
648 if (defined($errors[0])) {
649 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
651 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
652 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info of file: " . $collectedfonts{$fontname}->{$foundry}->{file});
655 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info from file: $file");
660 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
662 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
663 $collectedfonts{$fontname}->{$foundry}->{wprops} = $wprops;
664 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
665 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
670 for my $fontname (sort keys %collectedfonts) {
671 my @foundries = sort keys %{$collectedfonts{$fontname}};
672 my $printfoundries = 0;
673 if (defined($foundries[1])) {
676 for my $foundry (@foundries) {
677 if (exists($options{PrintWarnings})) {
678 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
682 my $fn = "Font : $fontname";
683 if ($printfoundries && ($foundry ne "")) {
684 $fn .= " \[$foundry\]";
687 print INFOS $fn if (defined($options{Write}));
688 print $collectedfonts{$fontname}->{$foundry}->{props};
689 print INFOS $collectedfonts{$fontname}->{$foundry}->{wprops} if (defined($options{Write}));
690 print INFOS ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n" if (defined($options{Write}));
691 if (exists($options{PrintFiles})) {
692 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
699 close(INFOS) if (defined($options{Write}));
702 #################################################################################
706 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
707 my ($x, $y) = ($1, $3);
709 $ilang = lc($x) . '-' . lc($y);
720 my ($l, $islang, $txt, $rres) = @_;
722 if ($l =~ /$txt=\"([^\"]+)\"/) {
723 @res = split(',', $1);
726 $lg = &convertlang($lg);
735 my ($lang, $rlangs) = @_;
738 for (my $i = 0; defined($rlangs->[$i]); $i++) {
739 if ($rlangs->[$i] eq $lang) {
748 my ($l, $txtval, $txtlang, $startentry) = @_;
751 &extractlist($l, 0, $txtval, \@values);
752 return("", -1) if (! defined($values[0]));
753 &extractlist($l, 1, $txtlang, \@langs);
754 my $i = &getIndexes("en", \@langs);
756 my $actualentry = -1;
759 if (defined($values[$k])) {
761 if ($startentry < 0) {
762 if (length($values[$k]) > length($res)) {
764 $usedentry = $actualentry;
767 elsif ($actualentry == $startentry) {
769 $usedentry = $actualentry;
773 # select the longest entry if possible
774 if (length($values[$k]) > length($res)) {
776 $usedentry = $actualentry;
781 return($values[0], -1) if ($res eq "");
782 return($res, $usedentry);
785 sub getsinglevalue($$$)
787 my ($l, $txt, $rMap, $rget) = @_;
789 if ($l =~ / $txt=(\d+)/) {
791 # Search for nearest value to $val
792 if (defined($rMap->{$val})) {
793 return($rMap->{$val});
797 for my $key (keys %{$rMap}) {
798 next if ($key !~ /^\d+$/);
799 my $diff = abs($key - $val);
804 elsif ($diff == $minv) {
810 if (! defined($rMap->{$maxv})) {
811 print "ERROR2: txt=$txt, val=$val\n";
815 return($rMap->{$maxv} . "+$minv");
818 return($rMap->{$maxv} . "-$minv");
828 my ($txt, $val) = @_;
829 return("$txt($val)");
834 my ($fontname, $style) = @_;
836 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
839 elsif ($fontname =~ /gothic|dotum|gulim/i) {
840 if ($fontname =~ /bisrat gothic/i) {
843 elsif ($fontname !~ /hershey/i) {
847 elsif ($fontname =~ /^(js ?math.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
848 $resftype |= DOUBLESTROKE; # Double stroke (math font)
850 if ($fontname =~ /serif|times|mincho|batang/i) {
851 $resftype |= SERIF; # Serif
853 if ($fontname =~ /initial(s|en)/i) {
854 $resftype |= INITIALS;
855 if ($fontname =~ /^linux ?libertine/i) {
859 if ($fontname =~ /participants/i) {
860 $resftype |= SANS|FANCY;
862 if ($fontname =~ /symbol|cherokee/i) {
863 if ($fontname !~ /^(symbola|asap)/i) {
865 if ($fontname =~ /^(ams ?math|computer modern bright msb)/i) {
866 $resftype |= DOUBLESTROKE | SERIF;
870 if ($fontname =~ /callig/i) {
873 if ($fontname =~ /\bS(mall)?C(aps)\b/i) {
874 if ($fontname !~ /^noto/i) {
875 $resftype |= SMALLCAP|SERIF;
878 # Now check for fonts without a hint in font name
879 if ($fontname =~ /^([a-z])/i) {
881 # check the mutual exclusive first
882 for my $rFonts (\%fraktFonts, \%scriptFonts, \%sansFonts, \%serifFonts) {
883 if (defined($rFonts->{$key})) {
884 if ($fontname =~ $rFonts->{$key}) {
885 $resftype |= $rFonts->{"value"};
890 for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts, \%smallcapFonts) {
891 if (defined($rFonts->{$key})) {
892 if ($fontname =~ $rFonts->{$key}) {
893 $resftype |= $rFonts->{"value"};
898 if ("$fontname" =~ /^bpg/i) {
899 if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
900 $resftype |= SERIF; # Serif
903 $resftype |= SANS; # Sans Serif
906 elsif ("$fontname" =~ /^dustismo/i) {
907 if ("$fontname" =~ /^dustismo roman/i) {
908 $resftype |= SERIF; # Serif
911 $resftype |= SANS; # Sans Serif
914 elsif ("$fontname" =~ /^go\b/i) {
915 if ("$fontname" =~ /^go mono/i) {
916 $resftype |= SERIF; # Serif
919 $resftype |= SANS; # Sans Serif
924 if ($resftype == 0) {
925 $resftype = $ftypes{default};
928 # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
929 if ($resftype & FRAKTUR) {
930 $resftype &= ~(SANS|SERIF|SCRIPT);
932 elsif ($resftype & SCRIPT) {
933 $resftype &= ~(SANS|SERIF);
935 elsif ($resftype & SANS) {
939 for (my $i = 1; $i < 513; $i *= 2) {
940 if ($resftype & $i) {
941 push(@ft, $ftypes{$i});
944 return(join(',', @ft));
949 my ($fontname, $style) = @_;
951 for my $info ($style, $fontname) {
952 for my $key (keys %weights) {
953 next if ($key !~ /^\d+$/);
954 my $val = $weights{$key};
955 if ($info =~ /\b$val\b/i) {
965 my ($fontname, $style) = @_;
967 for my $key (keys %widths) {
968 next if ($key !~ /^\d+$/);
969 for my $info ($style, $fontname) {
970 if ($info =~ /\b$widths{$key}\b/i) {
971 return($widths{$key});
973 if ($info =~ /\bRegular\b/) {
974 if (!defined($result)) {
975 $result = $widths{100};
985 my ($fontname, $style) = @_;
986 for my $key (keys %slants) {
987 next if ($key !~ /^\d+$/);
988 if ($style =~ /\b$slants{$key}\b/i) {
989 return($slants{$key});
997 my ($fontname, $style) = @_;
998 for my $key (keys %spacings) {
999 next if ($key !~ /^\d+$/);
1000 if ($style =~ /\b$spacings{$key}\b/i) {
1001 return($spacings{$key});
1004 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
1005 return($spacings{100}); # Mono
1014 my ($fontname, $rCapability) = @_;
1016 return 1 if ($fontname =~ /math/i);
1017 for my $cap (@{$rCapability}) {
1018 return 1 if ($cap eq "math");
1023 sub getproperties($$$$)
1025 my ($l, $fontname, $style, $rerrors) = @_;
1026 my $newstyle = &correctstyle($style);
1027 my $newfam = &correctstyle($fontname);
1028 my @properties = ();
1030 for my $txt (qw(ftype weight width slant spacing)) {
1032 eval("\$map = " . '\%' . $txt . 's');
1033 eval('$rget = \&' . "get$txt");
1034 my $val2 = getsinglevalue($l, $txt, $map);
1035 my $val1 = $rget->($newfam, $newstyle);
1037 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
1038 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/i)){
1039 # style overrides weight and slant
1040 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
1043 elsif ($newfam =~ /$val1/) {
1044 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
1048 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
1052 elsif (! defined($val2)) {
1058 if (defined($val)) {
1059 push(@properties, &addTxt($txt,$val));
1062 if (defined($map->{"default"})) {
1063 push(@properties, &addTxt($txt,$map->{"default"}));
1066 push(@{$rerrors}, "Undefined value for $txt");
1070 return(join(' ', @properties));
1076 $style =~ s/^\s*\d+\s*//;
1077 $style =~ s/\s*\d+$//;
1078 $style =~ s/italic/ Italic/i;
1079 $style =~ s/oblique/ Oblique/i;
1080 $style =~ s/[\-_]/ /g;
1081 $style =~ s/\breg\b/Regular/i;
1082 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
1083 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
1084 $style =~ s/medium/Medium /i;
1085 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
1086 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
1087 $style =~ s/\bmed\b/Medium /i;
1088 $style =~ s/\bex(pd|t)\b/Expanded/i;
1089 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
1090 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
1091 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
1092 $style =~ s/[sd]emi ?light/SemiLight/i;
1093 $style =~ s/\b[sd]emi\b/SemiBold/i;
1094 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
1095 $style =~ s/light/Light /i;
1096 $style =~ s/\blt\b/Light /i;
1097 $style =~ s/(ultra|extra) ?(light|lt)/ExtraLight /i;
1098 $style =~ s/\bheavy\b/Extrabold/i;
1099 $style =~ s/\bhairline\b/Extralight/i;
1100 $style =~ s/\bcond\b/Condensed/i;
1101 $style =~ s/(roman)?slanted/ Italic/i;
1102 $style =~ s/\bslant\b/Italic/i;
1103 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
1104 $style =~ s/w3 mono/Dual/i;
1105 $style =~ s/Regul[ea]r/Regular/i;
1106 $style =~ s/Megablack/ExtraBlack/i;
1112 # return list of unicode values of the input string
1113 #Allow input of intervals (e.g. 'a-z')
1114 sub decimalUnicode($)
1118 # Convert to unicode chars first
1119 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
1120 my ($prev, $d, $post) = ($1, $2, $3);
1121 if ($d =~ /^0?x(.+)$/) {
1124 my $chr = encode('utf-8', chr($d));
1125 $a = $prev . $chr . $post;
1127 # $a is now a string of unicode chars
1128 my $u = decode('utf-8', $a);
1129 my @a = split(//, $u);
1133 if ($x eq '-') { # Interval
1137 if ($interval && defined($start)) {
1138 if (ord($x) < $start) {
1139 for (my $i = $start - 1; $i >= ord($x); $i--) {
1144 for (my $i = $start + 1; $i <= ord($x); $i++) {
1160 # check if the glyph-values in interval @{$ri} are contained
1161 # in one of the (sorted) intervals
1165 # ...re0..........re1...
1166 # ......start..end......
1167 my ($ri, $rList) = @_;
1168 my $start = $ri->[0];
1171 for my $re (@{$rList}) {
1172 next if ($re->[1] < $start);
1173 # now we found a possible matching interval
1174 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1180 sub sprintIntervalls($)
1184 for my $rE (@{$rList}) {
1185 if ($rE->[0] != $rE->[1]) {
1186 push(@out, $rE->[0] . '-' . $rE->[1]);
1189 push(@out, $rE->[0]);
1192 return join(',', @out);
1195 sub buildFontName($$)
1197 my ($family, $style) = @_;
1200 $style =~ s/\\040//;
1201 $family =~ s/\\040/\-/;
1202 $family =~ s/\bcond\b/Condensed/i;
1203 $family =~ s/\bblk\b/Black/i;
1204 $family =~ s/\bsembd\b/SemiBold/i;
1205 $family =~ s/\bsemcond\b/SemiCondensed/i;
1206 $family =~ s/\bextcond\b/ExtraCondensed/i;
1207 $family =~ s/\bextbd\b/ExtraBold/i;
1208 $family =~ s/\bextlt\b/ExtraLight/i;
1209 $family =~ s/\bmed\b/Medium/i;
1210 if ($family =~ /^([A-Z]*[a-z]+)([A-Z]\w+)\b(.*)$/) {
1211 $family = $1 . splitatlU($2) . $3;
1213 $family =~ s/^Ant Polt\b/Antykwa Poltawskiego/;
1214 $family =~ s/\b(Semi|Extra) (Bold|Condensed|Expanded|Light)\b/$1$2/;
1215 my @style = &splitStyle($style);
1216 for my $st (@style) {
1218 if ($family !~ s/$st/$st/i) {
1222 # check if $st in $family starts with ' '
1223 $family =~ s/(\w)$st/$1 $st/i;
1227 return($result, join(' ', @style));
1230 # split text at change from lower case to upper case
1234 if ($txt =~ /^([A-Z]+[a-z]*)(.*)$/) {
1235 if (defined($mapShortcuts{$1})) {
1236 return(" " . $mapShortcuts{$1} . splitatlU($2));
1239 return(" $1" . splitatlU($2));
1247 my @in = split(/[- ]/, $_[0]);
1251 while ($en =~ s/^([A-Z][a-z]+)//) {
1253 if ($found =~ /^(Semi|Extra)$/) {
1257 elsif (defined($mapShortcuts{$found})) {
1258 $found = $mapShortcuts{$found};
1260 push(@result, "$prefix$found");
1264 push(@result, "$prefix$en");