]> git.lyx.org Git - features.git/blob - development/tools/listFontWithLang.pl
b6b1e0ae1869478fccb7f9534e87a651ffbf3857
[features.git] / development / tools / listFontWithLang.pl
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
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
8 #
9 # author Kornel Benko
10 # Full author contact details are available in the file CREDITS
11 # or at https://www.lyx.org/Credits
12 #
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 '--'
16 #
17 # Option to get list of options: -h
18 #
19 # Some equivalencies for instance with option -n
20 #       -n arial
21 #       -N=arial
22 #       --nAme=Arial
23 #       --name arial
24 # Options and option-parameter are case insensitive
25
26 BEGIN {
27     use File::Spec;
28     my $p = File::Spec->rel2abs( __FILE__ );
29     $p =~ s/[\/\\]?[^\/\\]+$//;
30     unshift(@INC, $p);
31 }
32
33 use strict;
34 use warnings;
35 use Encode;
36 use GetOptions;
37 use constant {
38   # for ftype
39   SERIF => 1,
40   SANS => 2,
41   SCRIPT => 4,
42   FRAKTUR => 8,
43   DOUBLESTROKE => 16,
44   FANCY => 32,
45   INITIALS => 64,
46   SYMBOL => 128,
47   SMALLCAP => 256,
48
49   # for UseProperty (UP)
50   UPPROPERTY => 1,         # select
51   UPNPROPERTY => 2,        # deselect
52   UPPPROPERTIES => 4,      # print
53   UPWPROPERTIES => 8,      # write to a file
54
55   # for UseCharsets (UC)
56   UCCONTAINS => 1,         # select
57   UCNCONTAINS => 2,        # deselect
58   UCPCONTAINS => 4,        # print
59
60   # for UseScripts (US)
61   USSCRIPT => 1,           # select
62   USNSCRIPT => 2,          # deselect
63   USMSCRIPT => 4,          # math
64   USPSCRIPT => 8,          # print
65   USWSCRIPT => 16,         # write to a file
66 };
67
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
72
73 sub convertlang($);
74 sub extractlist($$$);   # my ($l, $islang, $txt, $rres) = @_;
75 sub getIndexes($$);
76 sub getVal($$$$);       # my ($l, $txtval, $txtlang, $combine) = @_;
77 sub getproperties($$$$);
78 sub ismathfont($$);
79 sub correctstyle($);
80 sub decimalUnicode($);
81 sub contains($$);
82 sub sprintIntervalls($);
83 sub buildFontName($$);
84 sub splitatlU($);          # split text at change from lower case to upper case
85 sub splitStyle($);
86
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
93 my @optionsDef = (
94   # help + verbose already handled in 'GetOptions'
95   ["n",
96    {fieldname => "FontName", listsep => ',',
97     type => "=s", alias => ["name"],
98     comment => "Select font-names matching these (comma separated) regexes"},],
99   ["nn",
100    {fieldname => "NFontName",
101     type => "=s", listsep => ',',
102     comment => "Select font-names NOT matching these (comma separated) regexes"},],
103   ["p",
104    {fieldname => "Property",
105     type => "=s", listsep => ',',
106     comment => "Select fonts with properties matching these (comma separated) regexes"},],
107   ["np",
108    {fieldname => "NProperty",
109     type => "=s", listsep => ',',
110     comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
111   ["s",
112    {fieldname => "Scripts",
113     type => "=s", listsep => ',',
114     comment => "Select fonts with scripts matching these (comma separated) regexes"},],
115   ["ns",
116    {fieldname => "NScripts",
117     type => "=s", listsep => ',',
118     comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
119   ["math",
120    {fieldname => "Math",
121     comment => "Select fonts probably containing math glyphs"},],
122   ["c",
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\"",}],
127   ["nc",
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\"",}],
132   ["l",
133    {fieldname => "Lang",
134     type => "=s", alias=>["lang"],
135     comment => "Comma separated list of desired languages"},],
136   ["pc",
137    {fieldname => "PrintCharset", alias => ["printcharset"],
138     comment => "Print intervals of supported unicode character values"},],
139   ["pl",
140    {fieldname => "PrintLangs", alias => ["printlangs"],
141     comment => "Print supported languages"},],
142   ["pp",
143    {fieldname => "PrintProperties", alias => ["printproperties"],
144     comment => "Print properties from weight, slant and width"},],
145   ["ps",
146    {fieldname => "PrintScripts", alias => ["printscripts"],
147     comment => "Print supported scripts"},],
148   ["pf",
149    {fieldname => "PrintFiles", alias => ["printfiles"],
150     comment => "Print font file names"},],
151   ["pw",
152    {fieldname => "PrintWarnings",
153     comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
154   ["wf",
155    {fieldname => "Write",
156     type => "=s", alias => ["writefile"],
157     comment => "Write to a file for later use"},],
158 );
159 my %options = %{&handleOptions(\@optionsDef)};
160
161 $options{Lang} = "" if (! defined($options{Lang}));
162
163 #############################################################
164 my %mapShortcuts = (
165   "Cond" => "Condensed",
166   "Expd" => "Expanded",
167   "Lt"   => "Light",
168   "Med"  => "Medium",
169   "med"  => "Medium",
170   "bol"  => "Bold",
171 );
172
173 my @langs = split(',', $options{Lang});
174 for my $lg (@langs) {
175   $lg = &convertlang($lg);
176 }
177
178 $iproperty |= UPPROPERTY if (defined($options{Property}));
179 $iproperty |= UPNPROPERTY if (defined($options{NProperty}));
180 $iproperty |= UPPPROPERTIES if (exists($options{PrintProperties}));
181
182 $icontains |= UCCONTAINS if (defined($options{Contains}));
183 $icontains |= UCNCONTAINS if (defined($options{NContains}));
184 $icontains |= UCPCONTAINS if (exists($options{PrintCharset}));
185
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}));
190
191 if (defined($options{Write})) {
192   if (! open(INFOS, '>', $options{Write})) {
193     die("Could not open file $options{Write} for write");
194   }
195   $iproperty |= UPWPROPERTIES;
196   # not yet ...
197   # $iscript |= USWSCRIPT;
198 }
199
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)) {
205         $glyphs{$e} = 1;
206       }
207     }
208     # create intervalls
209     my @glyphs = sort {$a <=> $b;} keys %glyphs;
210
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)) {
216         $first = $i;
217         $last = $i;
218         next;
219       }
220       if ($i == $last+1) {
221         $last = $i;
222         next;
223       }
224       push(@{$options{$charFld}}, [$first, $last]);
225       $first = $i;
226       $last = $i;
227     }
228     if (defined($last)) {
229       push(@{$options{$charFld}}, [$first, $last]);
230     }
231     if (exists($options{verbose})) {
232       if ($charFld eq "Contains") {
233         print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
234       }
235       else {
236         print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
237       }
238     }
239   }
240 }
241
242 my $cmd = "fc-list";
243 if (defined($langs[0])) {
244   $cmd .= " :lang=" . join(',', @langs);
245 }
246
247 my $format = "foundry=\"%{foundry}\"" .
248     " postscriptname=\"%{postscriptname}\"" .
249     " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
250     " family=\"%{family}\" flang=\"%{familylang}\" " .
251     " style=\"%{style}\" stylelang=\"%{stylelang}\"";
252
253 if ($iscript) {
254   $format .= " script=\"%{capability}\"";
255 }
256 if (exists($options{PrintLangs}) || defined($langs[0])) {
257   $format .= " lang=\"%{lang}\"";
258 }
259 if ($iproperty) {
260   $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
261 }
262 if ($icontains) {
263   $format .= " charset=\"%{charset}\"";
264 }
265 $format .= " file=\"%{file}\" abcd\\n";
266 $cmd .= " -f '$format'";
267 #print "$cmd\n";
268
269
270 my %ftypes = (
271   # Dummy internal map
272   # using '()' to prevent the initializer to take
273   #    the key as a string. (Constants in perl _are_ functions without argument)
274   SERIF() => "Serif",
275   SANS() => "Sans",
276   SCRIPT() => "Script",
277   FRAKTUR() => "Fraktur",
278   DOUBLESTROKE() => "DoubleStroke",
279   FANCY() => "Fancy",
280   INITIALS() => "Initials",
281   SYMBOL() => "Symbol",
282   SMALLCAP() => "SmallCap",
283   "default" => 1,
284 );
285
286 my %weights = (
287   0 => "Thin",
288   40 => "Extralight",
289   50 => "Light",
290   55 => "Semilight",
291   75 => "Book",
292   80 => "Regular",
293   100 => "Medium",
294   180 => "Semibold",
295   200 => "Bold",
296   205 => "Extrabold",
297   210 => "Black",
298   215 => "ExtraBlack",
299 );
300
301 my %slants = (
302   0 => "Roman",
303   100 => "Italic",
304   110 => "Oblique",
305 );
306
307 my %widths = (
308   50 => "Ultracondensed",
309   63 => "Extracondensed",
310   75 => "Condensed",
311   87 => "Semicondensed",
312   100 => "Normal",
313   113 => "Semiexpanded",
314   125 => "Expanded",
315   150 => "Extraexpanded",
316   200 => "Ultraexpanded",
317 );
318
319 my %spacings = (
320   0 => "Proportional",
321   90 => "Dual",
322   100 => "Mono",
323   110 => "Charcell",
324   "default" => "Proportional",
325 );
326
327 # Build reverse mappings, (not needed yet)
328 for my $txt (qw(ftypes weights slants widths spacings)) {
329   my $map;
330   eval "\$map = \\%$txt";
331   for my $key (keys %{$map}) {
332     next if ($key !~ /^\d+$/);
333     my $value = lc($map->{$key});
334     $map->{"r"}->{$value} = $key;
335   }
336 }
337
338 # key:= fontname
339 #     subkey foundry
340 #            subfoundry
341 my %collectedfonts = ();
342 my %fontpriority = (
343   otf => 0,                # type 2, opentype CFF (Compact Font Format)
344   ttc => 1.1,              # type 1 (True Type font Collection)
345   ttf => 1.2,              # type 1 (True Type Font)
346   woff=> 1.3,              # type 1 (Web Open Font Format)
347   t1  => 1.4,              # type 1 (postscript)
348   pfb => 1.5,              # type 1 (Printer Font Binary)
349   pfa => 1.6,              # type 1 (Printer Font Ascii)
350   pfm => 2,                # requires associated .pfb file
351   pcf => 5,                # Bitmap (Packaged Collaboration Files)?
352 );
353 my $nexttype = 6;
354
355 my %serifFonts = (
356   # some extra serif fonts
357   "value" => SERIF,
358   "g" => qr/^gfs ?(didot)/i,
359 );
360 # list of regexes for known sans serif fonts
361 my %sansFonts = (
362   "value" => SANS,          # Sans serif
363   "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,
364   "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,
365   "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,
366   "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
367   "e" => qr/^(electron|engebrechtre)/i,
368   "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
369   "g" => qr/^g(ardiner|aruda|fs ?neo|illius|ood ?times|ranada|raph|uanine|unplay)/i,
370   "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
371   "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
372   "j" => qr/^j(ara|ura|s ?math.?bbold)/i,
373   "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kp ?mono|kurier|kustom)/i,
374   "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation ?mono|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
375   "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,
376   "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice|noto ?mono)/i,
377   "o" => qr/^(ocr|okolaks|open ?dyslexic|ostorah|ouhud|over|oxygen)/i,
378   "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
379   "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
380   "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
381   "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
382   "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
383   "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,
384   "v" => qr/^(veranda|vn ?urwclassico)/i,
385   "w" => qr/^(waree)/i,
386   "y" => qr/^(yanone)/i,
387   "z" => qr/^(zekton|zero)/i,
388 );
389 my %scriptFonts = (
390   "value" => SCRIPT,          # Script
391   "a" => qr/^a(becedario|ir ?cut|ugie|uriocus ?kalligraph)/i,
392   "b" => qr/^b(reip|rush ?script)/i,
393   "c" => qr/^(chancery)/i,
394   "d" => qr/^(dancing)/i,
395   "e" => qr/^(elegante)/i,
396   "f" => qr/^femkeklaver/i,
397   "j" => qr/^jsmath.?(rsfs)/i,
398   "k" => qr/^(kaushan|karumbi|kristi)/i,
399   "m" => qr/^(math ?jax.?script|miama)/i,
400   "n" => qr/^(nanum (brush|pen) script)/i,
401   "p" => qr/^pecita/i,
402   "q" => qr/^qt( ?black ?forest|arabian|boulevard|brush ?stroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
403   "r" => qr/^((romande.*|ruf)script|rsfs)/i,
404   "t" => qr/^typo ?script/i,
405   "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
406 );
407
408 my %fraktFonts = (
409   "value" => FRAKTUR,          # Fraktur
410   "b" => qr/^boondox ?fraktur/i,
411   "e" => qr/^eufm/i,
412   "j" => qr/^(jsmath.?euf)/i,
413   "m" => qr/^(missaali)/i,
414   "o" => qr/^(oldania)/i,
415   "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london) ?scroll)/i,
416   "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
417 );
418
419 my %fancyFonts = (
420   "value" => FANCY,          # Fancy
421   "a" => qr/^a(bandoned|bberancy|driator|irmole|lmendra ?display|lmonte (snow|woodgrain)|nalecta|ni|nklepants|nn ?stone|oyagi|rt ?nouveau ?caps|stron|xaxa)/i,
422   "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,
423   "c" => qr/^c(retino|msy|abin ?sketch|arbon|arolingan|harles|hicken|hilanka|hr\d)/i,
424   "d" => qr/^dseg/i,
425   "e" => qr/^electorate/i,
426   "f" => qr/^frederika/i,
427   "g" => qr/^(gfs.?theo)/i,
428   "j" => qr/^jsmath.cmsy/i,
429   "k" => qr/^keter|kicking|kredit|kouzan/i,
430   "l" => qr/^lcmsy/i,
431   "q" => qr/^qtcaslan ?open/i,
432   "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
433   "v" => qr/^vectroid/i,
434 );
435
436 my %initialFonts = (
437   "value" => INITIALS,          # Initials
438   "c" => qr/^carrick/i,
439   "e" => qr/^(eb.?garamond.?init)/i,
440   "t" => qr/^typographer/i,
441   "y" => qr/^(yinit)/i,
442 );
443
444 my %symbolFonts = (
445   "value" => SYMBOL,          # Symbol
446   "a" => qr/^a(cademicons|lblant|lianna|mar|nka|rb?\d|rchaic|rrow|rs|rt[mt]|ssy(rb\d+)?\b|miri ?quran|mit\b)/i,
447   "b" => qr/^b(aby ?jeepers|bding|euron|guq|lex|lsy|oondox ?upr|ullets|urma)/i,
448   "c" => qr/^c(aladings|cicons|hess|msy|mex|apacitor|ounterscraps)/i,
449   "d" => qr/^(dingbats|drmsym|d05)/i,
450   "e" => qr/^e(lusiveicons|mmentaler|moji|sint|uterpe)/i,
451   "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
452   "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot).?classic|complutum))/i,
453   "h" => qr/^h(ots|ershey)/i,
454   "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
455   "l" => qr/^l(cmsy|msam)/i,
456   "m" => qr/^(marvosym|material|msam|msbm)/i,
457   "n" => qr/^(noto.*(emoji|brahmi))/i,
458   "o" => qr/^(octicons)/i,
459   "p" => qr/^patch/i,
460   "q" => qr/^(qtding ?bits)/i,
461   "s" => qr/^s(emafor|kak|tmary|s?msam|tix ?math)/i,
462   "t" => qr/^(te ?xxslh?[du]|typicons|twemoji)/i,
463   "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
464   "w" => qr/^w(ebdings|asy|elfare ?brat)/i,
465 );
466
467 my %smallcapFonts = (
468   "value" => SMALLCAP | SERIF,
469   "c" => qr/^c(s[ct]sc\d|inzel|omputer ?modern ?sans ?italic ?regular ?\d)/i,
470   "d" => qr/^drm(it)?sc\d/i,
471   "f" => qr/^fetamont.?script/i,
472   "n" => qr/^newtxb?ttsc/i,
473   "s" => qr/^(screengem|sf.?kp.?sc)/i,
474   "t" => qr/^t1?xb?ttsc/i,
475   "v" => qr/^vn ?cccsc\d/i,
476 );
477
478 if (open(FI,  "$cmd |")) {
479  NXTLINE: while (my $l = <FI>) {
480     chomp($l);
481     while ($l !~ /abcd$/) {
482       $l .= <FI>;
483       chomp($l);
484     }
485     my $file = "";
486     my $fonttype;
487     if ($l =~ /file=\"([^\"]+)\"/) {
488       $file = $1;
489       #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
490       if ($file !~ /\.([a-z0-9]{2,5})$/i) {
491         print "Unhandled extension for file $file\n";
492         next;
493       }
494       $fonttype = lc($1);
495       if (! defined($fontpriority{$fonttype})) {
496         print "Added extension $fonttype for file $file\n";
497         $fontpriority{$fonttype} = $nexttype;
498         $nexttype++;
499       }
500     }
501     my %usedlangs = ();
502     if ($l =~ / lang=\"([^\"]+)\"/) {
503       my @ll = split(/\|/, $1);
504       for my $lx (@ll) {
505         $usedlangs{&convertlang($lx)} = 1;
506       }
507     }
508
509     for my $lang (@langs) {
510       next NXTLINE if (! defined($usedlangs{$lang}));
511     }
512     my ($fullname, $fuidx) = &getVal($l, "fn", "fnl", -1);
513     my ($style, $fsidx) = &getVal($l, "style", "stylelang", $fuidx);
514     $style =~ s/^\\040//;
515     my ($family, $faidx)  = &getVal($l, "family", "flang", $fsidx);
516
517     my $postscriptname = "";
518     if ($l =~ /postscriptname=\"([^\"]+)\"/) {
519       $postscriptname = $1;
520     }
521     my $fontname;
522     ($fontname, $style) = &buildFontName($family, $style);
523     if (defined($options{NFontName})) {
524       for my $fn (@{$options{NFontName}}) {
525         next NXTLINE if ($fontname =~ /$fn/i);
526       }
527     }
528     if (defined($options{FontName})) {
529       for my $fn (@{$options{FontName}}) {
530         next NXTLINE if ($fontname !~ /$fn/i);
531       }
532     }
533     my @charlist = ();
534     if ($icontains) {
535       if ($l =~ / charset=\"([^\"]+)\"/) {
536         my @list = split(/\s+/, $1);
537         for my $e (@list) {
538           my ($l, $h) = split('-', $e);
539           $h = $l if (! defined($h));
540           push(@charlist, [hex($l), hex($h)]);
541         }
542       }
543       if ($icontains & UCCONTAINS) {
544         for my $g (@{$options{Contains}}) {
545           next NXTLINE if (! contains($g, \@charlist));
546         }
547       }
548       if ($icontains & UCNCONTAINS) {
549         for my $g (@{$options{NContains}}) {
550           # Ignore if ANY char exist in @charlist
551           for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
552             next NXTLINE if (contains([$i,$i], \@charlist));
553           }
554         }
555       }
556     }
557     my $props = "";
558     my $wprops = "";
559     my @errors = ();
560     if ($iproperty) {
561       my $properties = getproperties($l, $fontname, $style, \@errors);
562       if ($iproperty & UPPROPERTY) {
563         for my $pn (@{$options{Property}}) {
564           next NXTLINE if ($properties !~ /$pn/i);
565         }
566       }
567       if ($iproperty & UPNPROPERTY) {
568         for my $pn (@{$options{NProperty}}) {
569           next NXTLINE if ($properties =~ /$pn/i);
570         }
571       }
572       if ($iproperty & UPPPROPERTIES) {
573         $props .= " ($properties)";
574       }
575       if ($iproperty & UPWPROPERTIES) {
576         $wprops .= " ($properties)";
577       }
578     }
579     if (exists($options{PrintLangs})) {
580       $props .= '(' . join(',', sort keys %usedlangs) . ')';
581     }
582     if (exists($options{PrintCharset})) {
583       $props .= '(' . &sprintIntervalls(\@charlist) . ')';
584     }
585     if ($iscript) {
586       my @scripts = ();
587       my $scripts = "";
588       if ($l =~ / script=\"([^\"]+)\"/) {
589         @scripts = split(/\s+/, $1);
590         for my $ent (@scripts) {
591           $ent =~ s/^\s*otlayout://;
592           $ent = lc($ent);
593         }
594         $scripts = join(',', @scripts);
595       }
596       if ($iscript & USMSCRIPT) {
597         next NXTLINE if (! &ismathfont($fontname,\@scripts));
598       }
599       if ($iscript & USPSCRIPT) {
600         $props .= "($scripts)";
601       }
602       if (!defined($scripts[0])) {
603         # No script defined in font, so check only $options{Scripts}
604         next NXTLINE if ($iscript & USSCRIPT);
605       }
606       else {
607         if ($iscript & USSCRIPT) {
608           for my $s (@{$options{Scripts}}) {
609             next NXTLINE if ($scripts !~ /$s/i);
610           }
611         }
612         if ($iscript & USNSCRIPT) {
613           for my $s (@{$options{NScripts}}) {
614             next NXTLINE if ($scripts =~ /$s/i);
615           }
616         }
617       }
618     }
619     my $foundry = "";
620     if ($l =~ /foundry=\"([^\"]+)\"/) {
621       $foundry = $1;
622       $foundry =~ s/^\s+//;
623       $foundry =~ s/\s+$//;
624     }
625     if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
626       # Apparently not the first one, so add some info
627       my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
628       if (defined($errors[0])) {
629         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
630       }
631       if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
632         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info of file: " . $collectedfonts{$fontname}->{$foundry}->{file});
633       }
634       else {
635         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info from file: $file");
636         next;
637       }
638     }
639     else {
640       $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
641     }
642     $collectedfonts{$fontname}->{$foundry}->{props} = $props;
643     $collectedfonts{$fontname}->{$foundry}->{wprops} = $wprops;
644     $collectedfonts{$fontname}->{$foundry}->{file} = $file;
645     $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
646   }
647   close(FI);
648 }
649
650 for my $fontname (sort keys %collectedfonts) {
651   my @foundries = sort keys %{$collectedfonts{$fontname}};
652   my $printfoundries = 0;
653   if (defined($foundries[1])) {
654     $printfoundries = 1;
655   }
656   for my $foundry (@foundries) {
657     if (exists($options{PrintWarnings})) {
658       for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
659         print "$err\n";
660       }
661     }
662     my $fn = "Font : $fontname";
663     if ($printfoundries && ($foundry ne "")) {
664       $fn .= " \[$foundry\]";
665     }
666     print $fn;
667     print INFOS $fn if (defined($options{Write}));
668     print $collectedfonts{$fontname}->{$foundry}->{props};
669     print INFOS $collectedfonts{$fontname}->{$foundry}->{wprops} if (defined($options{Write}));
670     print INFOS ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n" if (defined($options{Write}));
671     if (exists($options{PrintFiles})) {
672       print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
673     }
674     else {
675       print "\n";
676     }
677   }
678 }
679 close(INFOS) if (defined($options{Write}));
680
681 exit(0);
682 #################################################################################
683 sub convertlang($)
684 {
685   my ($ilang) = @_;
686   if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
687     my ($x, $y) = ($1, $3);
688     if (defined($y)) {
689       $ilang = lc($x) . '-' . lc($y);
690     }
691     else {
692       $ilang = lc($x);
693     }
694   }
695   return($ilang);
696 }
697
698 sub extractlist($$$)
699 {
700   my ($l, $islang, $txt, $rres) = @_;
701   my @res = ();
702   if ($l =~ /$txt=\"([^\"]+)\"/) {
703     @res = split(',', $1);
704     if ($islang) {
705       for my $lg (@res) {
706         $lg = &convertlang($lg);
707       }
708     }
709   }
710   @{$rres} = @res;
711 }
712
713 sub getIndexes($$)
714 {
715   my ($lang, $rlangs) = @_;
716   my @res = ();
717
718   for (my $i = 0; defined($rlangs->[$i]); $i++) {
719     if ($rlangs->[$i] eq $lang) {
720       push(@res, $i);
721     }
722   }
723   return(\@res);
724 }
725
726 sub getVal($$$$)
727 {
728   my ($l, $txtval, $txtlang, $startentry) = @_;
729   my @values = ();
730   my @langs = ();
731   &extractlist($l, 0, $txtval, \@values);
732   return("", -1) if (! defined($values[0]));
733   &extractlist($l, 1, $txtlang, \@langs);
734   my $i = &getIndexes("en", \@langs);
735   my $usedentry = -1;
736   my $actualentry = -1;
737   my $res = "";
738   for my $k (@{$i}) {
739     if (defined($values[$k])) {
740       $actualentry++;
741       if ($startentry < 0) {
742         if (length($values[$k]) > length($res)) {
743           $res = $values[$k];
744           $usedentry = $actualentry;
745         }
746       }
747       elsif ($actualentry == $startentry) {
748         $res = $values[$k];
749         $usedentry = $actualentry;
750         last;
751       }
752       else {
753         # select the longest entry if possible
754         if (length($values[$k]) > length($res)) {
755           $res = $values[$k];
756           $usedentry = $actualentry;
757         }
758       }
759     }
760   }
761   return($values[0], -1) if ($res eq "");
762   return($res, $usedentry);
763 }
764
765 sub getsinglevalue($$$)
766 {
767   my ($l, $txt, $rMap, $rget) = @_;
768   my $val;
769   if ($l =~ / $txt=(\d+)/) {
770     $val = $1;
771     # Search for nearest value to $val
772     if (defined($rMap->{$val})) {
773       return($rMap->{$val});
774     }
775     my $maxv = -1;
776     my $minv = 1000;
777     for my $key (keys %{$rMap}) {
778       next if ($key !~ /^\d+$/);
779       my $diff = abs($key - $val);
780       if ($diff < $minv) {
781         $maxv = $key;
782         $minv = $diff;
783       }
784       elsif ($diff == $minv) {
785         if ($key < $maxv) {
786           $maxv = $key;
787         }
788       }
789     }
790     if (! defined($rMap->{$maxv})) {
791       print "ERROR2: txt=$txt, val=$val\n";
792       exit(-2);
793     }
794     if ($val > $maxv) {
795       return($rMap->{$maxv} . "+$minv");
796     }
797     else {
798       return($rMap->{$maxv} . "-$minv");
799     }
800   }
801   else {
802     return(undef);
803   }
804 }
805
806 sub addTxt($$)
807 {
808   my ($txt, $val) = @_;
809   return("$txt($val)");
810 }
811
812 sub getftype($$)
813 {
814   my ($fontname, $style) = @_;
815   my $resftype = 0;
816   if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
817     $resftype |= SANS;
818   }
819   elsif ($fontname =~ /gothic|dotum|gulim/i) {
820     if ($fontname =~ /bisrat gothic/i) {
821       $resftype |= SERIF;
822     }
823     elsif ($fontname !~ /hershey/i) {
824       $resftype |= SANS;
825     }
826   }
827   elsif ($fontname =~ /^(js ?math.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
828     $resftype |= DOUBLESTROKE;  # Double stroke (math font)
829   }
830   if ($fontname =~ /serif|times|mincho|batang/i) {
831     $resftype |= SERIF; # Serif
832   }
833   if ($fontname =~ /initial(s|en)/i) {
834     $resftype |= INITIALS;
835     if ($fontname =~ /^linux ?libertine/i) {
836       $resftype |= SERIF;
837     }
838   }
839   if ($fontname =~ /participants/i) {
840     $resftype |= SANS|FANCY;
841   }
842   if ($fontname =~ /symbol|cherokee/i) {
843     if ($fontname !~ /^(symbola|asap)/i) {
844       $resftype |= SYMBOL;
845       if ($fontname =~ /^(ams ?math|computer modern bright msb)/i) {
846         $resftype |= DOUBLESTROKE | SERIF;
847       }
848     }
849   }
850   if ($fontname =~ /callig/i) {
851     $resftype |= FANCY;
852   }
853   if ($fontname =~ /\bS(mall)?C(aps)\b/i) {
854     if ($fontname !~ /^noto/i) {
855       $resftype |= SMALLCAP|SERIF;
856     }
857   }
858   # Now check for fonts without a hint in font name
859   if ($fontname =~ /^([a-z])/i) {
860     my $key = lc($1);
861     # check the mutual exclusive first
862     for my $rFonts (\%fraktFonts, \%scriptFonts, \%sansFonts, \%serifFonts) {
863       if (defined($rFonts->{$key})) {
864         if ($fontname =~ $rFonts->{$key}) {
865           $resftype |= $rFonts->{"value"};
866           last;
867         }
868       }
869     }
870     for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts, \%smallcapFonts) {
871       if (defined($rFonts->{$key})) {
872         if ($fontname =~ $rFonts->{$key}) {
873           $resftype |= $rFonts->{"value"};
874         }
875       }
876     }
877   }
878   if ("$fontname" =~ /^bpg/i) {
879     if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
880       $resftype |= SERIF;    # Serif
881     }
882     else {
883       $resftype |= SANS; # Sans Serif
884     }
885   }
886   elsif ("$fontname" =~ /^dustismo/i) {
887     if ("$fontname" =~ /^dustismo roman/i) {
888       $resftype |= SERIF;    # Serif
889     }
890     else {
891       $resftype |= SANS; # Sans Serif
892     }
893   }
894   elsif ("$fontname" =~ /^go\b/i) {
895     if ("$fontname" =~ /^go mono/i) {
896       $resftype |= SERIF;    # Serif
897     }
898     else {
899       $resftype |= SANS; # Sans Serif
900     }
901   }
902   # Create the string
903   my @ft = ();
904   if ($resftype == 0) {
905     $resftype = $ftypes{default};
906   }
907   else {
908     # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
909     if ($resftype & FRAKTUR) {
910       $resftype &= ~(SANS|SERIF|SCRIPT);
911     }
912     elsif ($resftype & SCRIPT) {
913       $resftype &= ~(SANS|SERIF);
914     }
915     elsif ($resftype & SANS) {
916       $resftype &= ~SERIF;
917     }
918   }
919   for (my $i = 1; $i < 513; $i *= 2) {
920     if ($resftype & $i) {
921       push(@ft, $ftypes{$i});
922     }
923   }
924   return(join(',', @ft));
925 }
926
927 sub getweight($$)
928 {
929   my ($fontname, $style) = @_;
930   my $result = undef;
931   for my $info ($style, $fontname) {
932     for my $key (keys %weights) {
933       next if ($key !~ /^\d+$/);
934       my $val = $weights{$key};
935       if ($info =~ /\b$val\b/i) {
936         return($val);
937       }
938     }
939   }
940   return($result);
941 }
942
943 sub getwidth($$)
944 {
945   my ($fontname, $style) = @_;
946   my $result = undef;
947   for my $key (keys %widths) {
948     next if ($key !~ /^\d+$/);
949     for my $info ($style, $fontname) {
950       if ($info =~ /\b$widths{$key}\b/i) {
951         return($widths{$key});
952       }
953       if ($info =~ /\bRegular\b/) {
954         if (!defined($result)) {
955           $result = $widths{100};
956         }
957       }
958     }
959   }
960   return($result);
961 }
962
963 sub getslant($$)
964 {
965   my ($fontname, $style) = @_;
966   for my $key (keys %slants) {
967     next if ($key !~ /^\d+$/);
968     if ($style =~ /\b$slants{$key}\b/i) {
969       return($slants{$key});
970     }
971   }
972   return(undef);
973 }
974
975 sub getspacing($$)
976 {
977   my ($fontname, $style) = @_;
978   for my $key (keys %spacings) {
979     next if ($key !~ /^\d+$/);
980     if ($style =~ /\b$spacings{$key}\b/i) {
981       return($spacings{$key});
982     }
983   }
984   if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
985     return($spacings{100}); # Mono
986   }
987   else {
988     return(undef);
989   }
990 }
991
992 sub ismathfont($$)
993 {
994   my ($fontname, $rCapability) = @_;
995
996   return 1 if ($fontname =~ /math/i);
997   for my $cap (@{$rCapability}) {
998     return 1 if ($cap eq "math");
999   }
1000   return 0;
1001 }
1002
1003 sub getproperties($$$$)
1004 {
1005   my ($l, $fontname, $style, $rerrors) = @_;
1006   my $newstyle = &correctstyle($style);
1007   my $newfam = &correctstyle($fontname);
1008   my @properties = ();
1009
1010   for my $txt (qw(ftype weight width slant spacing)) {
1011     my ($map, $rget);
1012     eval("\$map = " . '\%' . $txt . 's');
1013     eval('$rget = \&' . "get$txt");
1014     my $val2 = getsinglevalue($l, $txt, $map);
1015     my $val1 = $rget->($newfam, $newstyle);
1016     my $val;
1017     if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
1018       if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/i)){
1019         # style overrides weight and slant
1020         push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
1021         $val = $val1;
1022       }
1023       elsif ($newfam =~ /$val1/) {
1024         push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
1025         $val = $val1;
1026       }
1027       else {
1028         push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
1029         $val = $val2;
1030       }
1031     }
1032     elsif (! defined($val2)) {
1033       $val = $val1;
1034     }
1035     else {
1036       $val = $val2;
1037     }
1038     if (defined($val)) {
1039       push(@properties, &addTxt($txt,$val));
1040     }
1041     else {
1042       if (defined($map->{"default"})) {
1043         push(@properties, &addTxt($txt,$map->{"default"}));
1044       }
1045       else {
1046         push(@{$rerrors}, "Undefined value for $txt");
1047       }
1048     }
1049   }
1050   return(join(' ', @properties));
1051 }
1052
1053 sub correctstyle($)
1054 {
1055   my ($style) = @_;
1056   $style =~ s/^\s*\d+\s*//;
1057   $style =~ s/\s*\d+$//;
1058   $style =~ s/italic/ Italic/i;
1059   $style =~ s/oblique/ Oblique/i;
1060   $style =~ s/[\-_]/ /g;
1061   $style =~ s/\breg\b/Regular/i;
1062   $style =~ s/\bregita(lic)?\b/Regular Italic/i;
1063   $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
1064   $style =~ s/medium/Medium /i;
1065   $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
1066   $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
1067   $style =~ s/\bmed\b/Medium /i;
1068   $style =~ s/\bex(pd|t)\b/Expanded/i;
1069   $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
1070   $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
1071   $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
1072   $style =~ s/[sd]emi ?light/SemiLight/i;
1073   $style =~ s/\b[sd]emi\b/SemiBold/i;
1074   $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
1075   $style =~ s/light/Light /i;
1076   $style =~ s/\blt\b/Light /i;
1077   $style =~ s/(ultra|extra) ?(light|lt)/ExtraLight /i;
1078   $style =~ s/\bheavy\b/Extrabold/i;
1079   $style =~ s/\bhairline\b/Extralight/i;
1080   $style =~ s/\bcond\b/Condensed/i;
1081   $style =~ s/(roman)?slanted/ Italic/i;
1082   $style =~ s/\bslant\b/Italic/i;
1083   $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
1084   $style =~ s/w3 mono/Dual/i;
1085   $style =~ s/Regul[ea]r/Regular/i;
1086   $style =~ s/Megablack/ExtraBlack/i;
1087   $style =~ s/  +/ /g;
1088   $style =~ s/ +$//;
1089   return($style);
1090 }
1091
1092 # return list of unicode values of the input string
1093 #Allow input of intervals (e.g. 'a-z')
1094 sub decimalUnicode($)
1095 {
1096   my ($a) = @_;
1097   my @res = ();
1098   # Convert to unicode chars first
1099   while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
1100     my ($prev, $d, $post) = ($1, $2, $3);
1101     if ($d =~ /^0?x(.+)$/) {
1102       $d = hex($1);
1103     }
1104     my $chr = encode('utf-8', chr($d));
1105     $a = $prev . $chr . $post;
1106   }
1107   # $a is now a string of unicode chars
1108   my $u = decode('utf-8', $a);
1109   my @a = split(//, $u);
1110   my $interval = 0;
1111   my $start = undef;
1112   for my $x (@a) {
1113     if ($x eq '-') {    # Interval
1114       $interval = 1;
1115       next;
1116     }
1117     if ($interval && defined($start)) {
1118       if (ord($x) < $start) {
1119         for (my $i = $start - 1; $i >= ord($x); $i--) {
1120           push(@res, $i);
1121         }
1122       }
1123       else {
1124         for (my $i = $start + 1; $i <= ord($x); $i++) {
1125           push(@res, $i);
1126         }
1127       }
1128       $start = undef;
1129     }
1130     else {
1131       $start = ord($x);
1132       push(@res, $start);
1133     }
1134     $interval = 0;
1135   }
1136   return(@res);
1137 }
1138
1139
1140 # check if the glyph-values in interval @{$ri} are contained
1141 # in one of the (sorted) intervals
1142 sub contains($$)
1143 {
1144   # ok if
1145   # ...re0..........re1...
1146   # ......start..end......
1147   my ($ri, $rList) = @_;
1148   my $start = $ri->[0];
1149   my $end = $ri->[1];
1150
1151   for my $re (@{$rList}) {
1152     next if ($re->[1] < $start);
1153     # now we found a possible matching interval
1154     return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1155     return 0;
1156   }
1157   return 0;
1158 }
1159
1160 sub sprintIntervalls($)
1161 {
1162   my ($rList) = @_;
1163   my @out = ();
1164   for my $rE (@{$rList}) {
1165     if ($rE->[0] != $rE->[1]) {
1166       push(@out, $rE->[0] . '-' . $rE->[1]);
1167     }
1168     else {
1169       push(@out, $rE->[0]);
1170     }
1171   }
1172   return join(',', @out);
1173 }
1174
1175 sub buildFontName($$)
1176 {
1177   my ($family, $style) = @_;
1178
1179   my $result = "";
1180   $style =~ s/\\040//;
1181   $family =~ s/\\040/\-/;
1182   $family =~ s/\bcond\b/Condensed/i;
1183   $family =~ s/\bblk\b/Black/i;
1184   $family =~ s/\bsembd\b/SemiBold/i;
1185   $family =~ s/\bsemcond\b/SemiCondensed/i;
1186   $family =~ s/\bextcond\b/ExtraCondensed/i;
1187   $family =~ s/\bextbd\b/ExtraBold/i;
1188   $family =~ s/\bextlt\b/ExtraLight/i;
1189   $family =~ s/\bmed\b/Medium/i;
1190   if ($family =~ /^([A-Z]*[a-z]+)([A-Z]\w+)\b(.*)$/) {
1191     $family = $1 . splitatlU($2) . $3;
1192   }
1193   $family =~ s/^Ant Polt\b/Antykwa Poltawskiego/;
1194   $family =~ s/\b(Semi|Extra) (Bold|Condensed|Expanded|Light)\b/$1$2/;
1195   my @style = &splitStyle($style);
1196   for my $st (@style) {
1197     $st = ucfirst($st);
1198     if ($family !~ s/$st/$st/i) {
1199       $family .= " $st";
1200     }
1201     else {
1202       # check if $st in $family starts with ' '
1203       $family =~ s/(\w)$st/$1 $st/i;
1204     }
1205   }
1206   $result = $family;
1207   return($result, join(' ', @style));
1208 }
1209
1210 # split text at change from lower case to upper case
1211 sub splitatlU($)
1212 {
1213   my ($txt) = @_;
1214   if ($txt =~ /^([A-Z]+[a-z]*)(.*)$/) {
1215     if (defined($mapShortcuts{$1})) {
1216       return(" " . $mapShortcuts{$1} . splitatlU($2));
1217     }
1218     else {
1219       return(" $1" . splitatlU($2));
1220     }
1221   }
1222   return($txt);
1223 }
1224
1225 sub splitStyle($)
1226 {
1227   my @in = split(/[- ]/, $_[0]);
1228   my @result = ();
1229   my $prefix = "";
1230   for my $en (@in) {
1231     while ($en =~ s/^([A-Z][a-z]+)//) {
1232       my $found = $1;
1233       if ($found =~ /^(Semi|Extra)$/) {
1234         $prefix = $found;
1235         next;
1236       }
1237       elsif (defined($mapShortcuts{$found})) {
1238         $found = $mapShortcuts{$found};
1239       }
1240       push(@result, "$prefix$found");
1241       $prefix = "";
1242     }
1243     if ($en ne "") {
1244       push(@result, "$prefix$en");
1245       $prefix = "";
1246     }
1247   }
1248   return(@result);
1249 }