]> git.lyx.org Git - lyx.git/blob - development/tools/listFontWithLang.pl
64beba89ffe752f815f413381f43977e9129795e
[lyx.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 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);
250       my @ud = ();
251       for my $c (@u) {
252         push(@ud, $c, $fill);
253       }
254       my $ud = join('', @ud);
255       my $e1 = encode('utf-8', $ud);
256       $e1 =~ s/\\s\?$//;
257       $e = qr/$e1/i;
258     }
259   }
260 }
261
262 my $cmd = "fc-list";
263 if (defined($langs[0])) {
264   $cmd .= " :lang=" . join(',', @langs);
265 }
266
267 my $format = "foundry=\"%{foundry}\"" .
268     " postscriptname=\"%{postscriptname}\"" .
269     " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
270     " family=\"%{family}\" flang=\"%{familylang}\" " .
271     " style=\"%{style}\" stylelang=\"%{stylelang}\"";
272
273 if ($iscript) {
274   $format .= " script=\"%{capability}\"";
275 }
276 if (exists($options{PrintLangs}) || defined($langs[0])) {
277   $format .= " lang=\"%{lang}\"";
278 }
279 if ($iproperty) {
280   $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
281 }
282 if ($icontains) {
283   $format .= " charset=\"%{charset}\"";
284 }
285 $format .= " file=\"%{file}\" abcd\\n";
286 $cmd .= " -f '$format'";
287 #print "$cmd\n";
288
289
290 my %ftypes = (
291   # Dummy internal map
292   # using '()' to prevent the initializer to take
293   #    the key as a string. (Constants in perl _are_ functions without argument)
294   SERIF() => "Serif",
295   SANS() => "Sans",
296   SCRIPT() => "Script",
297   FRAKTUR() => "Fraktur",
298   DOUBLESTROKE() => "DoubleStroke",
299   FANCY() => "Fancy",
300   INITIALS() => "Initials",
301   SYMBOL() => "Symbol",
302   SMALLCAP() => "SmallCap",
303   "default" => 1,
304 );
305
306 my %weights = (
307   0 => "Thin",
308   40 => "Extralight",
309   50 => "Light",
310   55 => "Semilight",
311   75 => "Book",
312   80 => "Regular",
313   100 => "Medium",
314   180 => "Semibold",
315   200 => "Bold",
316   205 => "Extrabold",
317   210 => "Black",
318   215 => "ExtraBlack",
319 );
320
321 my %slants = (
322   0 => "Roman",
323   100 => "Italic",
324   110 => "Oblique",
325 );
326
327 my %widths = (
328   50 => "Ultracondensed",
329   63 => "Extracondensed",
330   75 => "Condensed",
331   87 => "Semicondensed",
332   100 => "Normal",
333   113 => "Semiexpanded",
334   125 => "Expanded",
335   150 => "Extraexpanded",
336   200 => "Ultraexpanded",
337 );
338
339 my %spacings = (
340   0 => "Proportional",
341   90 => "Dual",
342   100 => "Mono",
343   110 => "Charcell",
344   "default" => "Proportional",
345 );
346
347 # Build reverse mappings, (not needed yet)
348 for my $txt (qw(ftypes weights slants widths spacings)) {
349   my $map;
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;
355   }
356 }
357
358 # key:= fontname
359 #     subkey foundry
360 #            subfoundry
361 my %collectedfonts = ();
362 my %fontpriority = (
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)?
372 );
373 my $nexttype = 6;
374
375 my %serifFonts = (
376   # some extra serif fonts
377   "value" => SERIF,
378   "g" => qr/^gfs ?(didot)/i,
379 );
380 # list of regexes for known sans serif fonts
381 my %sansFonts = (
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,
408 );
409 my %scriptFonts = (
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,
421   "p" => qr/^pecita/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,
426 );
427
428 my %fraktFonts = (
429   "value" => FRAKTUR,          # Fraktur
430   "b" => qr/^boondox ?fraktur/i,
431   "e" => qr/^eufm/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,
437 );
438
439 my %fancyFonts = (
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,
444   "d" => qr/^dseg/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,
450   "l" => qr/^lcmsy/i,
451   "q" => qr/^qtcaslan ?open/i,
452   "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
453   "v" => qr/^vectroid/i,
454 );
455
456 my %initialFonts = (
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,
462 );
463
464 my %symbolFonts = (
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,
479   "p" => qr/^patch/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,
485 );
486
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,
496 );
497
498 if (open(FI,  "$cmd |")) {
499  NXTLINE: while (my $l = <FI>) {
500     chomp($l);
501     while ($l !~ /abcd$/) {
502       $l .= <FI>;
503       chomp($l);
504     }
505     my $file = "";
506     my $fonttype;
507     if ($l =~ /file=\"([^\"]+)\"/) {
508       $file = $1;
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";
512         next;
513       }
514       $fonttype = lc($1);
515       if (! defined($fontpriority{$fonttype})) {
516         print "Added extension $fonttype for file $file\n";
517         $fontpriority{$fonttype} = $nexttype;
518         $nexttype++;
519       }
520     }
521     my %usedlangs = ();
522     if ($l =~ / lang=\"([^\"]+)\"/) {
523       my @ll = split(/\|/, $1);
524       for my $lx (@ll) {
525         $usedlangs{&convertlang($lx)} = 1;
526       }
527     }
528
529     for my $lang (@langs) {
530       next NXTLINE if (! defined($usedlangs{$lang}));
531     }
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);
536
537     my $postscriptname = "";
538     if ($l =~ /postscriptname=\"([^\"]+)\"/) {
539       $postscriptname = $1;
540     }
541     my $fontname;
542     ($fontname, $style) = &buildFontName($family, $style);
543     if (defined($options{NFontName})) {
544       for my $fn (@{$options{NFontName}}) {
545         next NXTLINE if ($fontname =~ $fn);
546       }
547     }
548     if (defined($options{FontName})) {
549       for my $fn (@{$options{FontName}}) {
550         next NXTLINE if ($fontname !~ $fn);
551       }
552     }
553     my @charlist = ();
554     if ($icontains) {
555       if ($l =~ / charset=\"([^\"]+)\"/) {
556         my @list = split(/\s+/, $1);
557         for my $e (@list) {
558           my ($l, $h) = split('-', $e);
559           $h = $l if (! defined($h));
560           push(@charlist, [hex($l), hex($h)]);
561         }
562       }
563       if ($icontains & UCCONTAINS) {
564         for my $g (@{$options{Contains}}) {
565           next NXTLINE if (! contains($g, \@charlist));
566         }
567       }
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));
573           }
574         }
575       }
576     }
577     my $props = "";
578     my $wprops = "";
579     my @errors = ();
580     if ($iproperty) {
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);
585         }
586       }
587       if ($iproperty & UPNPROPERTY) {
588         for my $pn (@{$options{NProperty}}) {
589           next NXTLINE if ($properties =~ /$pn/i);
590         }
591       }
592       if ($iproperty & UPPPROPERTIES) {
593         $props .= " ($properties)";
594       }
595       if ($iproperty & UPWPROPERTIES) {
596         $wprops .= " ($properties)";
597       }
598     }
599     if (exists($options{PrintLangs})) {
600       $props .= '(' . join(',', sort keys %usedlangs) . ')';
601     }
602     if (exists($options{PrintCharset})) {
603       $props .= '(' . &sprintIntervalls(\@charlist) . ')';
604     }
605     if ($iscript) {
606       my @scripts = ();
607       my $scripts = "";
608       if ($l =~ / script=\"([^\"]+)\"/) {
609         @scripts = split(/\s+/, $1);
610         for my $ent (@scripts) {
611           $ent =~ s/^\s*otlayout://;
612           $ent = lc($ent);
613         }
614         $scripts = join(',', @scripts);
615       }
616       if ($iscript & USMSCRIPT) {
617         next NXTLINE if (! &ismathfont($fontname,\@scripts));
618       }
619       if ($iscript & USPSCRIPT) {
620         $props .= "($scripts)";
621       }
622       if (!defined($scripts[0])) {
623         # No script defined in font, so check only $options{Scripts}
624         next NXTLINE if ($iscript & USSCRIPT);
625       }
626       else {
627         if ($iscript & USSCRIPT) {
628           for my $s (@{$options{Scripts}}) {
629             next NXTLINE if ($scripts !~ /$s/i);
630           }
631         }
632         if ($iscript & USNSCRIPT) {
633           for my $s (@{$options{NScripts}}) {
634             next NXTLINE if ($scripts =~ /$s/i);
635           }
636         }
637       }
638     }
639     my $foundry = "";
640     if ($l =~ /foundry=\"([^\"]+)\"/) {
641       $foundry = $1;
642       $foundry =~ s/^\s+//;
643       $foundry =~ s/\s+$//;
644     }
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);
650       }
651       if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
652         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info of file: " . $collectedfonts{$fontname}->{$foundry}->{file});
653       }
654       else {
655         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info from file: $file");
656         next;
657       }
658     }
659     else {
660       $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
661     }
662     $collectedfonts{$fontname}->{$foundry}->{props} = $props;
663     $collectedfonts{$fontname}->{$foundry}->{wprops} = $wprops;
664     $collectedfonts{$fontname}->{$foundry}->{file} = $file;
665     $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
666   }
667   close(FI);
668 }
669
670 for my $fontname (sort keys %collectedfonts) {
671   my @foundries = sort keys %{$collectedfonts{$fontname}};
672   my $printfoundries = 0;
673   if (defined($foundries[1])) {
674     $printfoundries = 1;
675   }
676   for my $foundry (@foundries) {
677     if (exists($options{PrintWarnings})) {
678       for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
679         print "$err\n";
680       }
681     }
682     my $fn = "Font : $fontname";
683     if ($printfoundries && ($foundry ne "")) {
684       $fn .= " \[$foundry\]";
685     }
686     print $fn;
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";
693     }
694     else {
695       print "\n";
696     }
697   }
698 }
699 close(INFOS) if (defined($options{Write}));
700
701 exit(0);
702 #################################################################################
703 sub convertlang($)
704 {
705   my ($ilang) = @_;
706   if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
707     my ($x, $y) = ($1, $3);
708     if (defined($y)) {
709       $ilang = lc($x) . '-' . lc($y);
710     }
711     else {
712       $ilang = lc($x);
713     }
714   }
715   return($ilang);
716 }
717
718 sub extractlist($$$)
719 {
720   my ($l, $islang, $txt, $rres) = @_;
721   my @res = ();
722   if ($l =~ /$txt=\"([^\"]+)\"/) {
723     @res = split(',', $1);
724     if ($islang) {
725       for my $lg (@res) {
726         $lg = &convertlang($lg);
727       }
728     }
729   }
730   @{$rres} = @res;
731 }
732
733 sub getIndexes($$)
734 {
735   my ($lang, $rlangs) = @_;
736   my @res = ();
737
738   for (my $i = 0; defined($rlangs->[$i]); $i++) {
739     if ($rlangs->[$i] eq $lang) {
740       push(@res, $i);
741     }
742   }
743   return(\@res);
744 }
745
746 sub getVal($$$$)
747 {
748   my ($l, $txtval, $txtlang, $startentry) = @_;
749   my @values = ();
750   my @langs = ();
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);
755   my $usedentry = -1;
756   my $actualentry = -1;
757   my $res = "";
758   for my $k (@{$i}) {
759     if (defined($values[$k])) {
760       $actualentry++;
761       if ($startentry < 0) {
762         if (length($values[$k]) > length($res)) {
763           $res = $values[$k];
764           $usedentry = $actualentry;
765         }
766       }
767       elsif ($actualentry == $startentry) {
768         $res = $values[$k];
769         $usedentry = $actualentry;
770         last;
771       }
772       else {
773         # select the longest entry if possible
774         if (length($values[$k]) > length($res)) {
775           $res = $values[$k];
776           $usedentry = $actualentry;
777         }
778       }
779     }
780   }
781   return($values[0], -1) if ($res eq "");
782   return($res, $usedentry);
783 }
784
785 sub getsinglevalue($$$)
786 {
787   my ($l, $txt, $rMap, $rget) = @_;
788   my $val;
789   if ($l =~ / $txt=(\d+)/) {
790     $val = $1;
791     # Search for nearest value to $val
792     if (defined($rMap->{$val})) {
793       return($rMap->{$val});
794     }
795     my $maxv = -1;
796     my $minv = 1000;
797     for my $key (keys %{$rMap}) {
798       next if ($key !~ /^\d+$/);
799       my $diff = abs($key - $val);
800       if ($diff < $minv) {
801         $maxv = $key;
802         $minv = $diff;
803       }
804       elsif ($diff == $minv) {
805         if ($key < $maxv) {
806           $maxv = $key;
807         }
808       }
809     }
810     if (! defined($rMap->{$maxv})) {
811       print "ERROR2: txt=$txt, val=$val\n";
812       exit(-2);
813     }
814     if ($val > $maxv) {
815       return($rMap->{$maxv} . "+$minv");
816     }
817     else {
818       return($rMap->{$maxv} . "-$minv");
819     }
820   }
821   else {
822     return(undef);
823   }
824 }
825
826 sub addTxt($$)
827 {
828   my ($txt, $val) = @_;
829   return("$txt($val)");
830 }
831
832 sub getftype($$)
833 {
834   my ($fontname, $style) = @_;
835   my $resftype = 0;
836   if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
837     $resftype |= SANS;
838   }
839   elsif ($fontname =~ /gothic|dotum|gulim/i) {
840     if ($fontname =~ /bisrat gothic/i) {
841       $resftype |= SERIF;
842     }
843     elsif ($fontname !~ /hershey/i) {
844       $resftype |= SANS;
845     }
846   }
847   elsif ($fontname =~ /^(js ?math.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
848     $resftype |= DOUBLESTROKE;  # Double stroke (math font)
849   }
850   if ($fontname =~ /serif|times|mincho|batang/i) {
851     $resftype |= SERIF; # Serif
852   }
853   if ($fontname =~ /initial(s|en)/i) {
854     $resftype |= INITIALS;
855     if ($fontname =~ /^linux ?libertine/i) {
856       $resftype |= SERIF;
857     }
858   }
859   if ($fontname =~ /participants/i) {
860     $resftype |= SANS|FANCY;
861   }
862   if ($fontname =~ /symbol|cherokee/i) {
863     if ($fontname !~ /^(symbola|asap)/i) {
864       $resftype |= SYMBOL;
865       if ($fontname =~ /^(ams ?math|computer modern bright msb)/i) {
866         $resftype |= DOUBLESTROKE | SERIF;
867       }
868     }
869   }
870   if ($fontname =~ /callig/i) {
871     $resftype |= FANCY;
872   }
873   if ($fontname =~ /\bS(mall)?C(aps)\b/i) {
874     if ($fontname !~ /^noto/i) {
875       $resftype |= SMALLCAP|SERIF;
876     }
877   }
878   # Now check for fonts without a hint in font name
879   if ($fontname =~ /^([a-z])/i) {
880     my $key = lc($1);
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"};
886           last;
887         }
888       }
889     }
890     for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts, \%smallcapFonts) {
891       if (defined($rFonts->{$key})) {
892         if ($fontname =~ $rFonts->{$key}) {
893           $resftype |= $rFonts->{"value"};
894         }
895       }
896     }
897   }
898   if ("$fontname" =~ /^bpg/i) {
899     if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
900       $resftype |= SERIF;    # Serif
901     }
902     else {
903       $resftype |= SANS; # Sans Serif
904     }
905   }
906   elsif ("$fontname" =~ /^dustismo/i) {
907     if ("$fontname" =~ /^dustismo roman/i) {
908       $resftype |= SERIF;    # Serif
909     }
910     else {
911       $resftype |= SANS; # Sans Serif
912     }
913   }
914   elsif ("$fontname" =~ /^go\b/i) {
915     if ("$fontname" =~ /^go mono/i) {
916       $resftype |= SERIF;    # Serif
917     }
918     else {
919       $resftype |= SANS; # Sans Serif
920     }
921   }
922   # Create the string
923   my @ft = ();
924   if ($resftype == 0) {
925     $resftype = $ftypes{default};
926   }
927   else {
928     # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
929     if ($resftype & FRAKTUR) {
930       $resftype &= ~(SANS|SERIF|SCRIPT);
931     }
932     elsif ($resftype & SCRIPT) {
933       $resftype &= ~(SANS|SERIF);
934     }
935     elsif ($resftype & SANS) {
936       $resftype &= ~SERIF;
937     }
938   }
939   for (my $i = 1; $i < 513; $i *= 2) {
940     if ($resftype & $i) {
941       push(@ft, $ftypes{$i});
942     }
943   }
944   return(join(',', @ft));
945 }
946
947 sub getweight($$)
948 {
949   my ($fontname, $style) = @_;
950   my $result = undef;
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) {
956         return($val);
957       }
958     }
959   }
960   return($result);
961 }
962
963 sub getwidth($$)
964 {
965   my ($fontname, $style) = @_;
966   my $result = undef;
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});
972       }
973       if ($info =~ /\bRegular\b/) {
974         if (!defined($result)) {
975           $result = $widths{100};
976         }
977       }
978     }
979   }
980   return($result);
981 }
982
983 sub getslant($$)
984 {
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});
990     }
991   }
992   return(undef);
993 }
994
995 sub getspacing($$)
996 {
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});
1002     }
1003   }
1004   if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
1005     return($spacings{100}); # Mono
1006   }
1007   else {
1008     return(undef);
1009   }
1010 }
1011
1012 sub ismathfont($$)
1013 {
1014   my ($fontname, $rCapability) = @_;
1015
1016   return 1 if ($fontname =~ /math/i);
1017   for my $cap (@{$rCapability}) {
1018     return 1 if ($cap eq "math");
1019   }
1020   return 0;
1021 }
1022
1023 sub getproperties($$$$)
1024 {
1025   my ($l, $fontname, $style, $rerrors) = @_;
1026   my $newstyle = &correctstyle($style);
1027   my $newfam = &correctstyle($fontname);
1028   my @properties = ();
1029
1030   for my $txt (qw(ftype weight width slant spacing)) {
1031     my ($map, $rget);
1032     eval("\$map = " . '\%' . $txt . 's');
1033     eval('$rget = \&' . "get$txt");
1034     my $val2 = getsinglevalue($l, $txt, $map);
1035     my $val1 = $rget->($newfam, $newstyle);
1036     my $val;
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");
1041         $val = $val1;
1042       }
1043       elsif ($newfam =~ /$val1/) {
1044         push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
1045         $val = $val1;
1046       }
1047       else {
1048         push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
1049         $val = $val2;
1050       }
1051     }
1052     elsif (! defined($val2)) {
1053       $val = $val1;
1054     }
1055     else {
1056       $val = $val2;
1057     }
1058     if (defined($val)) {
1059       push(@properties, &addTxt($txt,$val));
1060     }
1061     else {
1062       if (defined($map->{"default"})) {
1063         push(@properties, &addTxt($txt,$map->{"default"}));
1064       }
1065       else {
1066         push(@{$rerrors}, "Undefined value for $txt");
1067       }
1068     }
1069   }
1070   return(join(' ', @properties));
1071 }
1072
1073 sub correctstyle($)
1074 {
1075   my ($style) = @_;
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;
1107   $style =~ s/  +/ /g;
1108   $style =~ s/ +$//;
1109   return($style);
1110 }
1111
1112 # return list of unicode values of the input string
1113 #Allow input of intervals (e.g. 'a-z')
1114 sub decimalUnicode($)
1115 {
1116   my ($a) = @_;
1117   my @res = ();
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(.+)$/) {
1122       $d = hex($1);
1123     }
1124     my $chr = encode('utf-8', chr($d));
1125     $a = $prev . $chr . $post;
1126   }
1127   # $a is now a string of unicode chars
1128   my $u = decode('utf-8', $a);
1129   my @a = split(//, $u);
1130   my $interval = 0;
1131   my $start = undef;
1132   for my $x (@a) {
1133     if ($x eq '-') {    # Interval
1134       $interval = 1;
1135       next;
1136     }
1137     if ($interval && defined($start)) {
1138       if (ord($x) < $start) {
1139         for (my $i = $start - 1; $i >= ord($x); $i--) {
1140           push(@res, $i);
1141         }
1142       }
1143       else {
1144         for (my $i = $start + 1; $i <= ord($x); $i++) {
1145           push(@res, $i);
1146         }
1147       }
1148       $start = undef;
1149     }
1150     else {
1151       $start = ord($x);
1152       push(@res, $start);
1153     }
1154     $interval = 0;
1155   }
1156   return(@res);
1157 }
1158
1159
1160 # check if the glyph-values in interval @{$ri} are contained
1161 # in one of the (sorted) intervals
1162 sub contains($$)
1163 {
1164   # ok if
1165   # ...re0..........re1...
1166   # ......start..end......
1167   my ($ri, $rList) = @_;
1168   my $start = $ri->[0];
1169   my $end = $ri->[1];
1170
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]));
1175     return 0;
1176   }
1177   return 0;
1178 }
1179
1180 sub sprintIntervalls($)
1181 {
1182   my ($rList) = @_;
1183   my @out = ();
1184   for my $rE (@{$rList}) {
1185     if ($rE->[0] != $rE->[1]) {
1186       push(@out, $rE->[0] . '-' . $rE->[1]);
1187     }
1188     else {
1189       push(@out, $rE->[0]);
1190     }
1191   }
1192   return join(',', @out);
1193 }
1194
1195 sub buildFontName($$)
1196 {
1197   my ($family, $style) = @_;
1198
1199   my $result = "";
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;
1212   }
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) {
1217     $st = ucfirst($st);
1218     if ($family !~ s/$st/$st/i) {
1219       $family .= " $st";
1220     }
1221     else {
1222       # check if $st in $family starts with ' '
1223       $family =~ s/(\w)$st/$1 $st/i;
1224     }
1225   }
1226   $result = $family;
1227   return($result, join(' ', @style));
1228 }
1229
1230 # split text at change from lower case to upper case
1231 sub splitatlU($)
1232 {
1233   my ($txt) = @_;
1234   if ($txt =~ /^([A-Z]+[a-z]*)(.*)$/) {
1235     if (defined($mapShortcuts{$1})) {
1236       return(" " . $mapShortcuts{$1} . splitatlU($2));
1237     }
1238     else {
1239       return(" $1" . splitatlU($2));
1240     }
1241   }
1242   return($txt);
1243 }
1244
1245 sub splitStyle($)
1246 {
1247   my @in = split(/[- ]/, $_[0]);
1248   my @result = ();
1249   my $prefix = "";
1250   for my $en (@in) {
1251     while ($en =~ s/^([A-Z][a-z]+)//) {
1252       my $found = $1;
1253       if ($found =~ /^(Semi|Extra)$/) {
1254         $prefix = $found;
1255         next;
1256       }
1257       elsif (defined($mapShortcuts{$found})) {
1258         $found = $mapShortcuts{$found};
1259       }
1260       push(@result, "$prefix$found");
1261       $prefix = "";
1262     }
1263     if ($en ne "") {
1264       push(@result, "$prefix$en");
1265       $prefix = "";
1266     }
1267   }
1268   return(@result);
1269 }