4 # file listFontWithLang.pl
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING
7 # or at http://www.lyx.org/about/licence.php
10 # Full author contact details are available in the file CREDITS
11 # or at https://www.lyx.org/Credits
13 # Usage: listFontWithLang.pl <options>
14 # Displays installed system font names selected by <options>
15 # Option-strings with more that 1 char need be prefixed by '--'
17 # Option to get list of options: -h
19 # Some equivalencies for instance with option -n
24 # Options and option-parameter are case insensitive
28 my $p = File::Spec->rel2abs( __FILE__ );
29 $p =~ s/[\/\\]?[^\/\\]+$//;
39 sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
41 sub getVal($$$); # my ($l, $txtval, $txtlang) = @_;
42 sub getproperties($$$$);
45 sub decimalUnicode($);
47 sub sprintIntervalls($);
49 # Following fields for a parameter can be defined:
50 # fieldname: Name of entry in %options
51 # type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
52 # alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
53 # listsep: Separator for multiple data
54 # comment: Parameter description
56 # help + verbose already handled in 'GetOptions'
58 {fieldname => "FontName", listsep => ',',
59 type => "=s", alias => ["name"],
60 comment => "Select font-names matching these (comma separated) regexes"},],
62 {fieldname => "NFontName",
63 type => "=s", listsep => ',',
64 comment => "Select font-names NOT matching these (comma separated) regexes"},],
66 {fieldname => "Property",
67 type => "=s", listsep => ',',
68 comment => "Select fonts with properties matching these (comma separated) regexes"},],
70 {fieldname => "NProperty",
71 type => "=s", listsep => ',',
72 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
74 {fieldname => "Scripts",
75 type => "=s", listsep => ',',
76 comment => "Select fonts with scripts matching these (comma separated) regexes"},],
78 {fieldname => "NScripts",
79 type => "=s", listsep => ',',
80 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
83 comment => "Select fonts probably containing math glyphs"},],
85 {fieldname => "Contains", alias => ["contains"],
86 type => "=s", listsep => ',',
87 comment => "Select fonts containing all these (possibly comma separated) glyphs",
88 comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
91 type => "=s", alias=>["lang"],
92 comment => "Comma separated list of desired languages"},],
94 {fieldname => "PrintCharset", alias => ["printcharset"],
95 comment => "Print intervals of supported unicode character values"},],
97 {fieldname => "PrintLangs", alias => ["printlangs"],
98 comment => "Print supported languages"},],
100 {fieldname => "PrintProperties", alias => ["printproperties"],
101 comment => "Print properties from weight, slant and width"},],
103 {fieldname => "PrintScripts", alias => ["printscripts"],
104 comment => "Print supported scripts"},],
106 {fieldname => "PrintFiles", alias => ["printfiles"],
107 comment => "Print font file names"},],
109 {fieldname => "PrintWarnings",
110 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
112 my %options = %{&handleOptions(\@optionsDef)};
114 $options{Lang} = "" if (! defined($options{Lang}));
116 #############################################################
118 my @langs = split(',', $options{Lang});
119 for my $lg (@langs) {
120 $lg = &convertlang($lg);
123 if (defined($options{Contains})) {
124 my %glyphs = (); # To ignore duplicates
125 for my $a1 (@{$options{Contains}}) {
126 for my $e (decimalUnicode($a1)) {
131 my @glyphs = sort {$a <=> $b;} keys %glyphs;
133 # $options{Contains} no longer needed, so use it for unicode-point intervalls
134 $options{Contains} = [];
135 my ($first, $last) = (undef, undef);
136 for my $i (@glyphs) {
137 if (! defined($last)) {
146 push(@{$options{Contains}}, [$first, $last]);
150 if (defined($last)) {
151 push(@{$options{Contains}}, [$first, $last]);
153 if (exists($options{verbose})) {
154 print "Checking for unicode-points: " . &sprintIntervalls($options{Contains}) . "\n";
159 if (defined($langs[0])) {
160 $cmd .= " :lang=" . join(',', @langs);
163 my $format = "foundry=\"%{foundry}\"" .
164 " postscriptname=\"%{postscriptname}\"" .
165 " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
166 " family=\"%{family}\" flang=\"%{familylang}\" " .
167 " style=\"%{style}\" stylelang=\"%{stylelang}\"";
169 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NSpripts}) || exists($options{Math})) {
170 $format .= " script=\"%{capability}\"";
172 if (exists($options{PrintLangs}) || defined($langs[0])) {
173 $format .= " lang=\"%{lang}\"";
175 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
176 $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
178 if (defined($options{Contains}) || exists($options{PrintCharset})) {
179 $format .= " charset=\"%{charset}\"";
181 $format .= " file=\"%{file}\" abcd\\n";
182 $cmd .= " -f '$format'";
194 "default" => "Serif",
219 50 => "Ultracondensed",
220 63 => "Extracondensed",
222 87 => "Semicondensed",
224 113 => "Semiexpanded",
226 150 => "Extraexpanded",
227 200 => "Ultraexpanded",
235 "default" => "Proportional",
238 # Build reverse mappings, (not needed yet)
239 for my $txt (qw(ftypes weights slants widths spacings)) {
241 eval "\$map = \\%$txt";
242 for my $key (keys %{$map}) {
243 next if ($key !~ /^\d+$/);
244 my $value = lc($map->{$key});
245 $map->{"r"}->{$value} = $key;
252 my %collectedfonts = ();
254 otf => 0, # type 2, opentype CFF (Compact Font Format)
255 ttc => 1.1, # type 1 (True Type font Collection)
256 ttf => 1.2, # type 1 (True Type Font)
257 woff=> 1.3, # type 1 (Web Open Font Format)
258 t1 => 1.4, # type 1 (postscript)
259 pfb => 1.5, # type 1 (Printer Font Binary)
260 pfa => 1.6, # type 1 (Printer Font Ascii)
261 pcf => 5, # Bitmap (Packaged Collaboration Files)?
265 # list of regexes for known sans serif fonts
267 "value" => 100, # Sans serif
268 "a" => qr/^(aharoni|arial|andika|angostura|anonymous|arab|aroania|arimo|asap)/i,
269 "b" => qr/^b(aekmuk|ebas|erenika|eteckna|euron|lue)/i,
270 "c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|hivo|mu bright|omfortaa|omic|oolvetica|ortoba|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
271 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
272 "e" => qr/^(electron|engebrechtre)/i,
273 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
274 "g" => qr/^(gardiner|garuda|gfs ?neo|gillius|granada|graph|guanine|gunplay)/i,
275 "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
276 "i" => qr/^(ibm plex|ikarius|inconsolata|induni.?h|iwona)/i,
277 "j" => qr/^(jara|jura)/i,
278 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kurier|kustom)/i,
279 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
280 "m" => qr/^m(\+ |anchu|anjari|arcellus|ashq|eera|etal|igmix|igu|ikachan|intspirit|iriam ?clm|ona|onlam|ono(fonto|id|isome|noki)|ontserrat|otoyal|ukti|usica)/i,
281 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
282 "o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
283 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
284 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
285 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
286 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
287 "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
288 "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,
289 "v" => qr/^(veranda|vn ?urwclassico)/i,
290 "w" => qr/^(waree)/i,
291 "y" => qr/^(yanone)/i,
292 "z" => qr/^(zekton|zero)/i,
295 "value" => 110, # Script
296 "c" => qr/^(chancery)/i,
297 "d" => qr/^(dancing)/i,
298 "e" => qr/^(elegante)/i,
299 "j" => qr/^jsmath.?(rsfs)/i,
300 "k" => qr/^(kaushan|karumbi|kristi)/i,
301 "m" => qr/^(mathjax_script|miama)/i,
302 "n" => qr/^(nanum (brush|pen) script)/i,
303 "q" => qr/^qt(arabian|boulevard|brushstroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
304 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
305 "u" => qr/^(un ?pilgi|urw ?chancery)/i,
309 "value" => 120, # Fraktur
311 "j" => qr/^(jsmath.?euf)/i,
312 "m" => qr/^(missaali)/i,
313 "o" => qr/^(oldania)/i,
314 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london)scroll)/i,
318 "value" => 130, # Fancy
319 "c" => qr/^(cretino)/i,
320 "g" => qr/^(gfs.?theo)/i,
321 "k" => qr/^keter|kicking|kredit|kouzan|kerkis calligraphic/i,
325 "value" => 140, # Initials
326 "e" => qr/^(eb.?garamond.?init)/i,
327 "l" => qr/^(libertinus|linux).*initials/i,
328 "y" => qr/^(yinit)/i,
332 "value" => 200, # Symbol
333 "a" => qr/^(academicons)/i,
334 "c" => qr/^(caladings|ccicons|chess|cmsy|cmex)/i,
335 "d" => qr/^(dingbats|drmsym)/i,
336 "e" => qr/^(elusiveicons|emoji|esint)/i,
337 "f" => qr/^(fdsymbol|fourierorns)/i,
339 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
340 "m" => qr/^(marvosym|material|msam|msbm)/i,
341 "n" => qr/^(noto.*emoji)/i,
342 "o" => qr/^(octicons)/i,
343 "q" => qr/^(qtdingbits)/i,
345 "t" => qr/^(typicons|twemoji)/i,
346 "w" => qr/^(webdings|wasy)/i,
349 if (open(FI, "$cmd |")) {
350 NXTLINE: while (my $l = <FI>) {
352 while ($l !~ /abcd$/) {
358 if ($l =~ /file=\"([^\"]+)\"/) {
360 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
361 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
362 print "Unhandled extension for file $file\n";
366 if (! defined($fontpriority{$fonttype})) {
367 print "Added extension $fonttype for file $file\n";
368 $fontpriority{$fonttype} = $nexttype;
373 if ($l =~ / lang=\"([^\"]+)\"/) {
374 my @ll = split(/\|/, $1);
376 $usedlangs{&convertlang($lx)} = 1;
380 for my $lang (@langs) {
381 next NXTLINE if (! defined($usedlangs{$lang}));
383 my $style = &getVal($l, "style", "stylelang");
384 $style =~ s/^\\040//;
385 my $fullname = &getVal($l, "fn", "fnl");
386 my $postscriptname = "";
387 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
388 $postscriptname = $1;
390 my $family = &getVal($l, "family", "flang");
391 $family =~ s/\\040/\-/;
393 if (length($fullname) < 3) {
394 if (length($postscriptname) < 2) {
395 $fontname = "$family $style";
398 $fontname = $postscriptname;
402 $fontname = $fullname;
404 if (defined($options{NFontName})) {
405 for my $fn (@{$options{NFontName}}) {
406 next NXTLINE if ($fontname =~ /$fn/i);
409 if (defined($options{FontName})) {
410 for my $fn (@{$options{FontName}}) {
411 next NXTLINE if ($fontname !~ /$fn/i);
415 if (defined($options{Contains}) || exists($options{PrintCharset})) {
416 if ($l =~ / charset=\"([^\"]+)\"/) {
417 my @list = split(/\s+/, $1);
419 my ($l, $h) = split('-', $e);
420 $h = $l if (! defined($h));
421 push(@charlist, [hex($l), hex($h)]);
424 if (defined($options{Contains})) {
425 for my $g (@{$options{Contains}}) {
426 next NXTLINE if (! contains($g, \@charlist));
432 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
433 my $properties = getproperties($l, $fontname, $style, \@errors);
434 if (defined($options{Property})) {
435 for my $pn (@{$options{Property}}) {
436 next NXTLINE if ($properties !~ /$pn/i);
439 if (defined($options{NProperty})) {
440 for my $pn (@{$options{NProperty}}) {
441 next NXTLINE if ($properties =~ /$pn/i);
444 if (exists($options{PrintProperties})) {
445 $props .= " ($properties)";
449 if (exists($options{PrintLangs})) {
450 $props .= '(' . join(',', sort keys %usedlangs) . ')';
452 if (exists($options{PrintCharset})) {
453 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
455 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
458 if ($l =~ / script=\"([^\"]+)\"/) {
459 @scripts = split(/\s+/, $1);
460 for my $ent (@scripts) {
461 $ent =~ s/^\s*otlayout://;
464 $scripts = join(',', @scripts);
466 if (exists($options{Math})) {
467 next NXTLINE if (! &ismathfont($fontname,\@scripts));
469 if (exists($options{PrintScripts})) {
470 $props .= "($scripts)";
472 if (!defined($scripts[0])) {
473 # No script defined in font, so check only $options{Scripts}
474 next NXTLINE if (defined($options{Scripts}));
477 if (defined($options{Scripts})) {
478 for my $s (@{$options{Scripts}}) {
479 next NXTLINE if ($scripts !~ /$s/i);
482 if (defined($options{NScripts})) {
483 for my $s (@{$options{NScripts}}) {
484 next NXTLINE if ($scripts =~ /$s/i);
490 if ($l =~ /foundry=\"([^\"]+)\"/) {
492 $foundry =~ s/^\s+//;
493 $foundry =~ s/\s+$//;
495 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
496 # Apparently not the first one, so add some info
497 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
498 if (defined($errors[0])) {
499 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
501 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
502 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info for file: " . $collectedfonts{$fontname}->{$foundry}->{file});
505 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info for file: $file");
510 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
512 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
513 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
514 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
519 for my $fontname (sort keys %collectedfonts) {
520 my @foundries = sort keys %{$collectedfonts{$fontname}};
521 my $printfoundries = 0;
522 if (defined($foundries[1])) {
525 for my $foundry (@foundries) {
526 if (exists($options{PrintWarnings})) {
527 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
531 my $fn = "Font : $fontname";
532 if ($printfoundries && ($foundry ne "")) {
533 $fn .= " \[$foundry\]";
536 print $collectedfonts{$fontname}->{$foundry}->{props};
537 if (exists($options{PrintFiles})) {
538 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
547 #################################################################################
551 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
552 my ($x, $y) = ($1, $3);
554 $ilang = lc($x) . '-' . lc($y);
565 my ($l, $islang, $txt, $rres) = @_;
567 if ($l =~ /$txt=\"([^\"]+)\"/) {
568 @res = split(',', $1);
571 $lg = &convertlang($lg);
580 my ($lang, $rlangs) = @_;
583 for (my $i = 0; defined($rlangs->[$i]); $i++) {
584 if ($rlangs->[$i] eq $lang) {
593 my ($l, $txtval, $txtlang) = @_;
596 &extractlist($l, 0, $txtval, \@values);
597 return("") if (! defined($values[0]));
598 &extractlist($l, 1, $txtlang, \@langs);
599 my $i = &getIndexes("en", \@langs);
602 if (defined($values[$k]) && (length($values[$k]) > length($res))) {
606 return($values[0]) if ($res eq "");
610 sub getsinglevalue($$$)
612 my ($l, $txt, $rMap, $rget) = @_;
614 if ($l =~ / $txt=(\d+)/) {
616 # Search for nearest value to $val
617 if (defined($rMap->{$val})) {
618 return($rMap->{$val});
622 for my $key (keys %{$rMap}) {
623 next if ($key !~ /^\d+$/);
624 my $diff = abs($key - $val);
629 elsif ($diff == $minv) {
635 if (! defined($rMap->{$maxv})) {
636 print "ERROR2: txt=$txt, val=$val\n";
640 return($rMap->{$maxv} . "+$minv");
643 return($rMap->{$maxv} . "-$minv");
653 my ($txt, $val) = @_;
654 return("$txt($val)");
659 my ($fontname, $style) = @_;
660 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
661 return($ftypes{100}); # Sans Serif
663 elsif ($fontname =~ /gothic|dotum|gulim/i) {
664 if ($fontname =~ /bisrat gothic/i) {
665 return($ftypes{0}); # Serif
668 return($ftypes{100}); # Sans Serif
671 elsif ($fontname =~ /serif|times|mincho|batang/i) {
672 if ($fontname =~ /good times/i) {
673 return($ftypes{100}); # Sans Serif
675 elsif ($fontname !~ /initials/i) {
676 return($ftypes{0}); # Serif
679 # Now check for fonts without a hint in font name
680 if ($fontname =~ /^([a-z])/i) {
682 for my $rFonts (\%sansFonts, \%scriptFonts, \%fraktFonts, \%fancyFonts, \%initialFonts, \%symbolFonts) {
683 if (defined($rFonts->{$key})) {
684 if ($fontname =~ $rFonts->{$key}) {
685 return($ftypes{$rFonts->{"value"}});
690 if ("$fontname" =~ /^bpg/i) {
691 if ("$fontname" =~ /bpg (courier gpl|elite)/i) {
692 return($ftypes{0}); # Serif
695 return($ftypes{100}); # Sans Serif
698 elsif ("$fontname" =~ /^dustismo/i) {
699 if ("$fontname" =~ /^dustismo roman/i) {
700 return($ftypes{0}); # Serif
703 return($ftypes{100}); # Sans Serif
706 elsif ("$fontname" =~ /^go\b/i) {
707 if ("$fontname" =~ /^go mono/i) {
708 return($ftypes{0}); # Serif
711 return($ftypes{100}); # Sans Serif
721 my ($fontname, $style) = @_;
723 for my $info ($style, $fontname) {
724 for my $key (keys %weights) {
725 next if ($key !~ /^\d+$/);
726 my $val = $weights{$key};
727 if ($info =~ /\b$val\b/i) {
737 my ($fontname, $style) = @_;
739 for my $key (keys %widths) {
740 next if ($key !~ /^\d+$/);
741 for my $info ($style, $fontname) {
742 if ($info =~ /\b$widths{$key}\b/i) {
743 return($widths{$key});
745 if ($info =~ /\bRegular\b/) {
746 if (!defined($result)) {
747 $result = $widths{100};
757 my ($fontname, $style) = @_;
758 for my $key (keys %slants) {
759 next if ($key !~ /^\d+$/);
760 if ($style =~ /\b$slants{$key}\b/i) {
761 return($slants{$key});
769 my ($fontname, $style) = @_;
770 for my $key (keys %spacings) {
771 next if ($key !~ /^\d+$/);
772 if ($style =~ /\b$spacings{$key}\b/i) {
773 return($spacings{$key});
776 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
777 return($spacings{100}); # Mono
786 my ($fontname, $rCapability) = @_;
788 return 1 if ($fontname =~ /math/i);
789 for my $cap (@{$rCapability}) {
790 return 1 if ($cap eq "math");
795 sub getproperties($$$$)
797 my ($l, $fontname, $style, $rerrors) = @_;
798 my $newstyle = &correctstyle($style);
799 my $newfam = &correctstyle($fontname);
802 for my $txt (qw(ftype weight width slant spacing)) {
804 eval("\$map = " . '\%' . $txt . 's');
805 eval('$rget = \&' . "get$txt");
806 my $val2 = getsinglevalue($l, $txt, $map);
807 my $val1 = $rget->($newfam, $newstyle);
809 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
810 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/)){
811 # style overrides weight and slant
812 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
815 elsif ($newfam =~ /$val1/) {
816 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
820 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
824 elsif (! defined($val2)) {
831 push(@properties, &addTxt($txt,$val));
834 if (defined($map->{"default"})) {
835 push(@properties, &addTxt($txt,$map->{"default"}));
838 push(@{$rerrors}, "Undefined value for $txt");
842 return(join(' ', @properties));
848 $style =~ s/^\\040//;
849 $style =~ s/^\s*\d+\s*//;
850 $style =~ s/\s*\d+$//;
851 $style =~ s/italic/ Italic/i;
852 $style =~ s/oblique/ Oblique/i;
853 $style =~ s/[\-_]/ /g;
854 $style =~ s/\breg\b/Regular/i;
855 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
856 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
857 $style =~ s/medium/Medium /i;
858 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
859 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
860 $style =~ s/\bmed\b/Medium /i;
861 $style =~ s/\bdemi\b/SemiBold/i;
862 $style =~ s/\bex(pd|t)\b/Expanded/i;
863 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
864 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
865 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
866 $style =~ s/[sd]emi ?light/SemiLight/i;
867 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
868 $style =~ s/light/Light /i;
869 $style =~ s/\blt\b/Light /i;
870 $style =~ s/(ultra|extra)(light|lt)/ExtraLight /i;
871 $style =~ s/\bheavy\b/Extrabold/i;
872 $style =~ s/\bhairline\b/Extralight/i;
873 $style =~ s/\bcond\b/Condensed/i;
874 $style =~ s/(roman)?slanted/ Italic/i;
875 $style =~ s/\bslant\b/Italic/i;
876 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
877 $style =~ s/w3 mono/Dual/i;
878 $style =~ s/Regul[ea]r/Regular/i;
879 $style =~ s/Megablack/ExtraBlack/i;
884 # return list of unicode values of the input string
885 #Allow input of intervals (e.g. 'a-z')
886 sub decimalUnicode($)
890 # Convert to unicode chars first
891 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
892 my ($prev, $d, $post) = ($1, $2, $3);
893 if ($d =~ /^0?x(.+)$/) {
896 my $chr = encode('utf-8', chr($d));
897 $a = $prev . $chr . $post;
899 # $a is now a string of unicode chars
900 my $u = decode('utf-8', $a);
901 my @a = split(//, $u);
905 if ($x eq '-') { # Interval
909 if ($interval && defined($start)) {
910 if (ord($x) < $start) {
911 for (my $i = $start - 1; $i >= ord($x); $i--) {
916 for (my $i = $start + 1; $i <= ord($x); $i++) {
932 # check if the glyph-values in interval @{$ri} are contained
933 # in one of the (sorted) intervals
937 # ...re0..........re1...
938 # ......start..end......
939 my ($ri, $rList) = @_;
940 my $start = $ri->[0];
943 for my $re (@{$rList}) {
944 next if ($re->[1] < $start);
945 # now we found a possible matching interval
946 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
952 sub sprintIntervalls($)
956 for my $rE (@{$rList}) {
957 if ($rE->[0] != $rE->[1]) {
958 push(@out, $rE->[0] . '-' . $rE->[1]);
961 push(@out, $rE->[0]);
964 return join(',', @out);