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