]> git.lyx.org Git - features.git/blob - development/tools/listFontWithLang.pl
Tools: recognize most sans serif fonts in listFontWithLang.pl
[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 GetOptions;
36
37 sub convertlang($);
38 sub extractlist($$$);   # my ($l, $islang, $txt, $rres) = @_;
39 sub getIndex($$);
40 sub getVal($$$);        # my ($l, $txtval, $txtlang) = @_;
41 sub getproperties($$$$);
42 sub ismathfont($$);
43 sub correctstyle($);
44
45 # Following fields for a parameter can be defined:
46 # fieldname:         Name of entry in %options
47 # type:              [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
48 # alias:             reference to a list of aliases e.g. ["alias1", "alias2", ... ]
49 # listsep:           Separator for multiple data
50 # comment:           Parameter description
51 my %optionsDef = (
52   # help + verbose already handled in 'GetOptions'
53   "l"       => {fieldname => "Lang",
54                 type => "=s", alias=>["lang"],
55                 comment => "Comma separated list of desired languages"},
56   "math"    => {fieldname => "Math",
57                 comment => "Select fonts probably containing math glyphs"},
58   "n"       => {fieldname => "FontName", listsep => ',',
59                 type => "=s", alias => ["name"],
60                 comment => "Select font-names matching these (comma separated) regexes"},
61   "nn"      => {fieldname => "NFontName",
62                 type => "=s", listsep => ',',
63                 comment => "Select font-names NOT matching these (comma separated) regexes"},
64   "pl"      => {fieldname => "PrintLangs", alias => ["printlangs"],
65                 comment => "Print supported languages"},
66   "pf"      => {fieldname => "PrintFiles", alias => ["printfiles"],
67                 comment => "Print font file names"},
68   "p"       => {fieldname => "Property",
69                 type => "=s", listsep => ',',
70                 comment => "Select fonts with properties matching these (comma separated) regexes"},
71   "np"      => {fieldname => "NProperty",
72                 type => "=s", listsep => ',',
73                 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},
74   "pp"      => {fieldname => "PrintProperties", alias => ["printproperties"],
75                 comment => "Print properties from weight, slant and width"},
76   "s"       => {fieldname => "Scripts",
77                 type => "=s", listsep => ',',
78                 comment => "Select fonts with scripts matching these (comma separated) regexes"},
79   "ns"      => {fieldname => "NScripts",
80                 type => "=s", listsep => ',',
81                 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},
82   "ps"      => {fieldname => "PrintScripts", alias => ["printscripts"],
83                 comment => "Print supported scripts"},
84   "pw"      => {fieldname => "PrintWarnings",
85                 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},
86 );
87 my %options = %{&handleOptions(\%optionsDef)};
88
89 $options{Lang} = "" if (! defined($options{Lang}));
90
91 #############################################################
92
93 my @langs = split(',', $options{Lang});
94 for my $lg (@langs) {
95   $lg = &convertlang($lg);
96 }
97
98 my $cmd = "fc-list";
99 if (defined($langs[0])) {
100   $cmd .= " :lang=" . join(',', @langs);
101 }
102
103 my $format = "foundry=\"%{foundry}\" postscriptname=\"%{postscriptname}\" fn=\"%{fullname}\" fnl=\"%{fullnamelang}\" family=\"%{family}\" flang=\"%{familylang}\" style=\"%{style}\" stylelang=\"%{stylelang}\"";
104
105 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NSpripts}) || exists($options{Math})) {
106   $format .= " script=\"%{capability}\"";
107 }
108 if (exists($options{PrintLangs}) || defined($langs[0])) {
109   $format .= " lang=\"%{lang}\"";
110 }
111 if (exists($options{PrintProperties}) || defined($options{Property})) {
112   $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
113 }
114 $format .= " file=\"%{file}\" abcd\\n";
115 $cmd .= " -f '$format'";
116 #print "$cmd\n";
117
118 my %ftypes = (
119   # Dummy internal map
120   0 => "Serif",
121   100 => "Sans",
122   "default" => "Serif",
123 );
124
125 my %weights = (
126   0 => "Thin",
127   40 => "Extralight",
128   50 => "Light",
129   55 => "Semilight",
130   75 => "Book",
131   80 => "Regular",
132   100 => "Medium",
133   180 => "Semibold",
134   200 => "Bold",
135   205 => "Extrabold",
136   210 => "Black",
137 );
138
139 my %slants = (
140   0 => "Roman",
141   100 => "Italic",
142   110 => "Oblique",
143 );
144
145 my %widths = (
146   50 => "Ultracondensed",
147   63 => "Extracondensed",
148   75 => "Condensed",
149   87 => "Semicondensed",
150   100 => "Normal",
151   113 => "Semiexpanded",
152   125 => "Expanded",
153   150 => "Extraexpanded",
154   200 => "Ultraexpanded",
155 );
156
157 my %spacings = (
158   0 => "Proportional",
159   90 => "Dual",
160   100 => "Mono",
161   110 => "Charcell",
162   "default" => "Proportional",
163 );
164
165 # Build reverse mappings, (not needed yet)
166 for my $txt (qw(ftypes weights slants widths spacings)) {
167   my $map;
168   eval "\$map = \\%$txt";
169   for my $key (keys %{$map}) {
170     next if ($key !~ /^\d+$/);
171     my $value = lc($map->{$key});
172     $map->{"r"}->{$value} = $key;
173   }
174 }
175
176 # key:= fontname
177 #     subkey foundry
178 #            subfoundry
179 my %collectedfonts = ();
180 my %fontpriority = (
181   otf => 0,                # type 2, opentype CFF (Compact Font Format)
182   ttc => 1.1,              # type 1 (True Type font Collection)
183   ttf => 1.2,              # type 1 (True Type Font)
184   woff=> 1.3,              # type 1 (Web Open Font Format)
185   t1  => 1.4,              # type 1 (postscript)
186   pfb => 1.5,              # type 1 (Printer Font Binary)
187   pfa => 1.6,              # type 1 (Printer Font Ascii)
188   pcf => 5,                # Bitmap (Packaged Collaboration Files)?
189 );
190 my $nexttype = 6;
191
192 # list of regexes for known sans serif fonts
193 my %sansFonts = (
194   "a" => qr/^(arial|andika|angostura|anonymous|arab|aroania|arimo|asap)/i,
195   "b" => qr/^(baekmuk|bebas|berenika|beteckna|beuron|blue)/i,
196   "c" => qr/^(cabin|caliban|cantarell|carbon|carlito|chandas|chivo|cmu bright|comfortaa|comic|cortoba|cousine|cuprum|cwtex(hei|yen)|cyklop|cypro)/i,
197   "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
198   "e" => qr/^(electron|engebrechtre)/i,
199   "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
200   "g" => qr/^(gardiner|garuda|gfs ?neo|gillius|granada|graph|guanine|gunplay)/i,
201   "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
202   "i" => qr/^(ibm plex|ikarius|inconsolata|induni.?h|iwona)/i,
203   "j" => qr/^(jara|jura)/i,
204   "k" => qr/^(kalimati|kanji|karla|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|komatu|kurier)/i,
205   "l" => qr/^(laksaman|larabie|lato|league|lexend|lexigulim|libel|liberation|libre franklin|libris|linux biolinum|lobster|logix|lohit|loma)/i,
206   "m" => qr/^(m\+ |manchu|manjari|marcellus|mashq|meera|metal|migmix|migu|mikachan|mintspirit|mona|monlam|mono(fonto|id|isome|noki)|montserrat|motoyal|mukti|musica)/i,
207   "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
208   "o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
209   "p" => qr/^(padauk|padmaa|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
210   "q" => qr/^(qt(ancient|helvet|avanti|eratype|eurotype|floraline|florencia|frank|fritz|future|greece|howard|letter|optimum|pandora)|quercus)/i,
211   "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
212   "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
213   "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
214   "u" => qr/^(ubuntu|ukij (bom|chechek|cjk|diwani|ekran|elipbe|inchike|jelliy|kufi|qara|qolyazma|teng|title|tor)|umpush|un ?(dinaru|jamo|graphic|taza|vada|yetgul)|uni(kurd|space|versalis)|uroob|urw ?classico)/i,
215   "v" => qr/^(veranda|vn ?urwclassico)/i,
216   "w" => qr/^(waree)/i,
217   "y" => qr/^(yanone)/i,
218   "z" => qr/^(zekton|zero)/i,
219 );
220 if (open(FI,  "$cmd |")) {
221  NXTLINE: while (my $l = <FI>) {
222     chomp($l);
223     while ($l !~ /abcd$/) {
224       $l .= <FI>;
225       chomp($l);
226     }
227     my $file = "";
228     my $fonttype;
229     if ($l =~ /file=\"([^\"]+)\"/) {
230       $file = $1;
231       #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
232       if ($file !~ /\.([a-z0-9]{2,5})$/i) {
233         print "Unhandled extension for file $file\n";
234         next;
235       }
236       $fonttype = lc($1);
237       if (! defined($fontpriority{$fonttype})) {
238         print "Added extension $fonttype for file $file\n";
239         $fontpriority{$fonttype} = $nexttype;
240         $nexttype++;
241       }
242     }
243     my $nfound = 0;
244     my %usedlangs = ();
245     if ($l =~ / lang=\"([^\"]+)\"/) {
246       my @ll = split(/\|/, $1);
247       for my $lx (@ll) {
248         $usedlangs{&convertlang($lx)} = 1;
249       }
250     }
251
252     for my $lang (@langs) {
253       next NXTLINE if (! defined($usedlangs{$lang}));
254     }
255     next if ($nfound);
256     my $style = &getVal($l, "style", "stylelang");
257     $style =~ s/^\\040//;
258     my $fullname = &getVal($l, "fn", "fnl");
259     my $postscriptname = "";
260     if ($l =~ /postscriptname=\"([^\"]+)\"/) {
261       $postscriptname = $1;
262     }
263     my $family = &getVal($l, "family", "flang");
264     $family =~ s/\\040/\-/;
265     my $fontname;
266     if (length($fullname) < 3) {
267       if (length($postscriptname) < 2) {
268         $fontname = "$family $style";
269       }
270       else {
271         $fontname = $postscriptname;
272       }
273     }
274     else {
275       $fontname = $fullname;
276     }
277     if (defined($options{NFontName})) {
278       for my $fn (@{$options{NFontName}}) {
279         next NXTLINE if ($fontname =~ /$fn/i);
280       }
281     }
282     if (defined($options{FontName})) {
283       for my $fn (@{$options{FontName}}) {
284         next NXTLINE if ($fontname !~ /$fn/i);
285       }
286     }
287     my $props = "";
288     my @errors = ();
289     if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
290       my $properties = getproperties($l, $fontname, $style, \@errors);
291       if (defined($options{Property})) {
292         for my $pn (@{$options{Property}}) {
293           next NXTLINE if ($properties !~ /$pn/i);
294         }
295       }
296       if (defined($options{NProperty})) {
297         for my $pn (@{$options{NProperty}}) {
298           next NXTLINE if ($properties =~ /$pn/i);
299         }
300       }
301       if (exists($options{PrintProperties})) {
302         $props .= " ($properties)";
303       }
304     }
305
306     if (exists($options{PrintLangs})) {
307       $props .= '(' . join(',', sort keys %usedlangs) . ')';
308     }
309     if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
310       my @scripts = ();
311       my $scripts = "";
312       if ($l =~ / script=\"([^\"]+)\"/) {
313         @scripts = split(/\s+/, $1);
314         for my $ent (@scripts) {
315           $ent =~ s/^\s*otlayout://;
316           $ent = lc($ent);
317         }
318         $scripts = join(',', @scripts);
319       }
320       if (exists($options{Math})) {
321         next NXTLINE if (! &ismathfont($fontname,\@scripts));
322       }
323       if (exists($options{PrintScripts})) {
324         $props .= "($scripts)";
325       }
326       if (!defined($scripts[0])) {
327         # No script defined in font, so check only $options{Scripts}
328         next NXTLINE if (defined($options{Scripts}));
329       }
330       else {
331         if (defined($options{Scripts})) {
332           for my $s (@{$options{Scripts}}) {
333             next NXTLINE if ($scripts !~ /$s/i);
334           }
335         }
336         if (defined($options{NScripts})) {
337           for my $s (@{$options{NScripts}}) {
338             next NXTLINE if ($scripts =~ /$s/i);
339           }
340         }
341       }
342     }
343     my $foundry = "";
344     if ($l =~ /foundry=\"([^\"]+)\"/) {
345       $foundry = $1;
346       $foundry =~ s/^\s+//;
347       $foundry =~ s/\s+$//;
348     }
349     if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
350       # Apparently not the first one, so add some info
351       my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
352       if (defined($errors[0])) {
353         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
354       }
355       if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
356         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info for file: " . $collectedfonts{$fontname}->{$foundry}->{file});
357       }
358       else {
359         push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info for file: $file");
360         next;
361       }
362     }
363     else {
364       $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
365     }
366     $collectedfonts{$fontname}->{$foundry}->{props} = $props;
367     $collectedfonts{$fontname}->{$foundry}->{file} = $file;
368     $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
369   }
370   close(FI);
371 }
372
373 for my $fontname (sort keys %collectedfonts) {
374   my @foundries = sort keys %{$collectedfonts{$fontname}};
375   my $printfoundries = 0;
376   if (defined($foundries[1])) {
377     $printfoundries = 1;
378   }
379   for my $foundry (@foundries) {
380     if (exists($options{PrintWarnings})) {
381       for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
382         print "$err\n";
383       }
384     }
385     my $fn = "Font : $fontname";
386     if ($printfoundries && ($foundry ne "")) {
387       $fn .= " \[$foundry\]";
388     }
389     print $fn;
390     print $collectedfonts{$fontname}->{$foundry}->{props};
391     if (exists($options{PrintFiles})) {
392       print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
393     }
394     else {
395       print "\n";
396     }
397   }
398 }
399
400 exit(0);
401 #################################################################################
402 sub convertlang($)
403 {
404   my ($ilang) = @_;
405   if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
406     my ($x, $y) = ($1, $3);
407     if (defined($y)) {
408       $ilang = lc($x) . '-' . lc($y);
409     }
410     else {
411       $ilang = lc($x);
412     }
413   }
414   return($ilang);
415 }
416
417 sub extractlist($$$)
418 {
419   my ($l, $islang, $txt, $rres) = @_;
420   my @res = ();
421   if ($l =~ /$txt=\"([^\"]+)\"/) {
422     @res = split(',', $1);
423     if ($islang) {
424       for my $lg (@res) {
425         $lg = &convertlang($lg);
426       }
427     }
428   }
429   @{$rres} = @res;
430 }
431
432 sub getIndexes($$)
433 {
434   my ($lang, $rlangs) = @_;
435   my @res = ();
436
437   for (my $i = 0; defined($rlangs->[$i]); $i++) {
438     if ($rlangs->[$i] eq $lang) {
439       push(@res, $i);
440     }
441   }
442   return(\@res);
443 }
444
445 sub getVal($$$)
446 {
447   my ($l, $txtval, $txtlang) = @_;
448   my @values = ();
449   my @langs = ();
450   &extractlist($l, 0, $txtval, \@values);
451   return("") if (! defined($values[0]));
452   &extractlist($l, 1, $txtlang, \@langs);
453   my $i = &getIndexes("en", \@langs);
454   my $res = "";
455   for my $k (@{$i}) {
456     if (defined($values[$k]) && (length($values[$k]) > length($res))) {
457       $res = $values[$k];
458     }
459   }
460   return($values[0]) if ($res eq "");
461   return($res);
462 }
463
464 sub getsinglevalue($$$)
465 {
466   my ($l, $txt, $rMap, $rget) = @_;
467   my $val;
468   if ($l =~ / $txt=(\d+)/) {
469     $val = $1;
470     # Search for nearest value to $val
471     if (defined($rMap->{$val})) {
472       return($rMap->{$val});
473     }
474     my $maxv = -1;
475     my $minv = 1000;
476     for my $key (keys %{$rMap}) {
477       next if ($key !~ /^\d+$/);
478       my $diff = abs($key - $val);
479       if ($diff < $minv) {
480         $maxv = $key;
481         $minv = $diff;
482       }
483       elsif ($diff == $minv) {
484         if ($key < $maxv) {
485           $maxv = $key;
486         }
487       }
488     }
489     if (! defined($rMap->{$maxv})) {
490       print "ERROR2: txt=$txt, val=$val\n";
491       exit(-2);
492     }
493     if ($val > $maxv) {
494       return($rMap->{$maxv} . "+$minv");
495     }
496     else {
497       return($rMap->{$maxv} . "-$minv");
498     }
499   }
500   else {
501     return(undef);
502   }
503 }
504
505 sub addTxt($$)
506 {
507   my ($txt, $val) = @_;
508   return("$txt($val)");
509 }
510
511 sub getftype($$)
512 {
513   my ($fontname, $style) = @_;
514   if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
515     return($ftypes{100}); # Sans Serif
516   }
517   elsif ($fontname =~ /gothic|dotum|gulim/i) {
518     if ($fontname =~ /bisrat gothic/i) {
519       return($ftypes{0});    # Serif
520     }
521     else {
522       return($ftypes{100}); # Sans Serif
523     }
524   }
525   elsif ($fontname =~ /serif|times|mincho|batang/i) {
526     if ($fontname =~ /good times/i) {
527       return($ftypes{100}); # Sans Serif
528     }
529     else {
530       return($ftypes{0});    # Serif
531     }
532   }
533   # Now check for fonts without a hint in font name
534   if ($fontname =~ /([a-z])/i) {
535     my $key = lc($1);
536     if (defined($sansFonts{$key})) {
537       if ($fontname =~ $sansFonts{$key}) {
538         return($ftypes{100}); # Sans Serif
539       }
540     }
541   }
542   if ("$fontname" =~ /^bpg/i) {
543     if ("$fontname" =~ /bpg (courier gpl|elite)/i) {
544       return($ftypes{0});    # Serif
545     }
546     else {
547       return($ftypes{100}); # Sans Serif
548     }
549   }
550   elsif ("$fontname" =~ /^dustismo/i) {
551     if ("$fontname" =~ /^dustismo roman/i) {
552       return($ftypes{0});    # Serif
553     }
554     else {
555       return($ftypes{100}); # Sans Serif
556     }
557   }
558   elsif ("$fontname" =~ /^go\b/i) {
559     if ("$fontname" =~ /^go mono/i) {
560       return($ftypes{0});    # Serif
561     }
562     else {
563       return($ftypes{100}); # Sans Serif
564     }
565   }
566   else {
567     return(undef);
568   }
569 }
570
571 sub getweight($$)
572 {
573   my ($fontname, $style) = @_;
574   my $result = undef;
575   for my $key (keys %weights) {
576     next if ($key !~ /^\d+$/);
577     my $val = $weights{$key};
578     for my $info ($style, $fontname) {
579       if ($info =~ /\b$val\b/i) {
580         if ($val eq "Regular") {
581           $result = $val;    # It may refer to width
582         }
583         else {
584           return($val);
585         }
586       }
587     }
588   }
589   return($result);
590 }
591
592 sub getwidth($$)
593 {
594   my ($fontname, $style) = @_;
595   my $result = undef;
596   for my $key (keys %widths) {
597     next if ($key !~ /^\d+$/);
598     for my $info ($style, $fontname) {
599       if ($info =~ /\b$widths{$key}\b/i) {
600         return($widths{$key});
601       }
602       if ($info =~ /\bRegular\b/) {
603         if (!defined($result)) {
604           $result = $widths{100};
605         }
606       }
607     }
608   }
609   return($result);
610 }
611
612 sub getslant($$)
613 {
614   my ($fontname, $style) = @_;
615   for my $key (keys %slants) {
616     next if ($key !~ /^\d+$/);
617     if ($style =~ /\b$slants{$key}\b/i) {
618       return($slants{$key});
619     }
620   }
621   return(undef);
622 }
623
624 sub getspacing($$)
625 {
626   my ($fontname, $style) = @_;
627   for my $key (keys %spacings) {
628     next if ($key !~ /^\d+$/);
629     if ($style =~ /\b$spacings{$key}\b/i) {
630       return($spacings{$key});
631     }
632   }
633   if ("$fontname $style" =~ /(mono|typewriter|cursor|fixed)\b/i) {
634     return($spacings{100}); # Mono
635   }
636   else {
637     return(undef);
638   }
639 }
640
641 sub ismathfont($$)
642 {
643   my ($fontname, $rCapability) = @_;
644
645   return 1 if ($fontname =~ /math/i);
646   for my $cap (@{$rCapability}) {
647     return 1 if ($cap eq "math");
648   }
649   return 0;
650 }
651
652 sub getproperties($$$$)
653 {
654   my ($l, $fontname, $style, $rerrors) = @_;
655   my $newstyle = &correctstyle($style);
656   my $newfam = &correctstyle($fontname);
657   my @properties = ();
658
659   for my $txt (qw(ftype weight width slant spacing)) {
660     my ($map, $rget);
661     eval("\$map = " . '\%' . $txt . 's');
662     eval('$rget = \&' . "get$txt");
663     my $val2 = getsinglevalue($l, $txt, $map);
664     my $val1 = $rget->($newfam, $newstyle);
665     my $val;
666     if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
667       push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, selecting internal $txt($val2)");
668       $val = $val2;
669     }
670     elsif (! defined($val2)) {
671       $val = $val1;
672     }
673     else {
674       $val = $val2;
675     }
676     if (defined($val)) {
677       push(@properties, &addTxt($txt,$val));
678     }
679     else {
680       if (defined($map->{"default"})) {
681         push(@properties, &addTxt($txt,$map->{"default"}));
682       }
683       else {
684         push(@{$rerrors}, "Undefined value for $txt");
685       }
686     }
687   }
688   return(join(' ', @properties));
689 }
690
691 sub correctstyle($)
692 {
693   my ($style) = @_;
694   $style =~ s/^\\040//;
695   $style =~ s/^\s*\d+\s*//;
696   $style =~ s/\s*\d+$//;
697   $style =~ s/italic/ Italic/i;
698   $style =~ s/oblique/ Oblique/i;
699   $style =~ s/[\-_]/ /g;
700   $style =~ s/\breg\b/Regular/i;
701   $style =~ s/\bregita(lic)?\b/Regular Italic/i;
702   $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
703   $style =~ s/medium/Medium /i;
704   $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
705   $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
706   $style =~ s/\bmed\b/Medium /i;
707   $style =~ s/\bdemi\b/SemiBold/i;
708   $style =~ s/\bex(pd|t)\b/Expanded/i;
709   $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
710   $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
711   $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
712   $style =~ s/[sd]emi ?light/SemiLight/i;
713   $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
714   $style =~ s/light/Light /i;
715   $style =~ s/\blt\b/Light /i;
716   $style =~ s/(ultra|extra)(light|lt)/ExtraLight /i;
717   $style =~ s/\bheavy\b/Extrabold/i;
718   $style =~ s/\bhairline\b/Extralight/i;
719   $style =~ s/\bcond\b/Condensed/i;
720   $style =~ s/(roman)?slanted/ Italic/i;
721   $style =~ s/\bslant\b/Italic/i;
722   $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
723   $style =~ s/w3 mono/Dual/i;
724   $style =~ s/Regul[ea]r/Regular/i;
725   $style =~ s/  +/ /g;
726   return($style);
727 }