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/[\/\\]?[^\/\\]+$//;
49 sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
51 sub getVal($$$$); # my ($l, $txtval, $txtlang, $combine) = @_;
52 sub getproperties($$$$);
55 sub decimalUnicode($);
57 sub sprintIntervalls($);
58 sub buildFontName($$$$);
60 # Following fields for a parameter can be defined:
61 # fieldname: Name of entry in %options
62 # type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
63 # alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
64 # listsep: Separator for multiple data
65 # comment: Parameter description
67 # help + verbose already handled in 'GetOptions'
69 {fieldname => "FontName", listsep => ',',
70 type => "=s", alias => ["name"],
71 comment => "Select font-names matching these (comma separated) regexes"},],
73 {fieldname => "NFontName",
74 type => "=s", listsep => ',',
75 comment => "Select font-names NOT matching these (comma separated) regexes"},],
77 {fieldname => "Property",
78 type => "=s", listsep => ',',
79 comment => "Select fonts with properties matching these (comma separated) regexes"},],
81 {fieldname => "NProperty",
82 type => "=s", listsep => ',',
83 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
85 {fieldname => "Scripts",
86 type => "=s", listsep => ',',
87 comment => "Select fonts with scripts matching these (comma separated) regexes"},],
89 {fieldname => "NScripts",
90 type => "=s", listsep => ',',
91 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
94 comment => "Select fonts probably containing math glyphs"},],
96 {fieldname => "Contains", alias => ["contains"],
97 type => "=s", listsep => ',',
98 comment => "Select fonts containing all these (possibly comma separated) glyphs",
99 comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
101 {fieldname => "NContains",
102 type => "=s", listsep => ',',
103 comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
104 comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
106 {fieldname => "Lang",
107 type => "=s", alias=>["lang"],
108 comment => "Comma separated list of desired languages"},],
110 {fieldname => "PrintCharset", alias => ["printcharset"],
111 comment => "Print intervals of supported unicode character values"},],
113 {fieldname => "PrintLangs", alias => ["printlangs"],
114 comment => "Print supported languages"},],
116 {fieldname => "PrintProperties", alias => ["printproperties"],
117 comment => "Print properties from weight, slant and width"},],
119 {fieldname => "PrintScripts", alias => ["printscripts"],
120 comment => "Print supported scripts"},],
122 {fieldname => "PrintFiles", alias => ["printfiles"],
123 comment => "Print font file names"},],
125 {fieldname => "PrintWarnings",
126 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
128 my %options = %{&handleOptions(\@optionsDef)};
130 $options{Lang} = "" if (! defined($options{Lang}));
132 #############################################################
134 my @langs = split(',', $options{Lang});
135 for my $lg (@langs) {
136 $lg = &convertlang($lg);
139 for my $charFld ("Contains", "NContains") {
140 if (defined($options{$charFld})) {
141 my %glyphs = (); # To ignore duplicates
142 for my $a1 (@{$options{$charFld}}) {
143 for my $e (decimalUnicode($a1)) {
148 my @glyphs = sort {$a <=> $b;} keys %glyphs;
150 # $options{$charFld} no longer needed, so use it for unicode-point intervalls
151 $options{$charFld} = [];
152 my ($first, $last) = (undef, undef);
153 for my $i (@glyphs) {
154 if (! defined($last)) {
163 push(@{$options{$charFld}}, [$first, $last]);
167 if (defined($last)) {
168 push(@{$options{$charFld}}, [$first, $last]);
170 if (exists($options{verbose})) {
171 if ($charFld eq "Contains") {
172 print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
175 print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
182 if (defined($langs[0])) {
183 $cmd .= " :lang=" . join(',', @langs);
186 my $format = "foundry=\"%{foundry}\"" .
187 " postscriptname=\"%{postscriptname}\"" .
188 " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
189 " family=\"%{family}\" flang=\"%{familylang}\" " .
190 " style=\"%{style}\" stylelang=\"%{stylelang}\"";
192 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
193 $format .= " script=\"%{capability}\"";
195 if (exists($options{PrintLangs}) || defined($langs[0])) {
196 $format .= " lang=\"%{lang}\"";
198 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
199 $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
201 if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
202 $format .= " charset=\"%{charset}\"";
204 $format .= " file=\"%{file}\" abcd\\n";
205 $cmd .= " -f '$format'";
211 # using '()' to prevent the initializer to take
212 # the key as a string. (Constants in perl _are_ functions without argument)
215 SCRIPT() => "Script",
216 FRAKTUR() => "Fraktur",
217 DOUBLESTROKE() => "DoubleStroke",
219 INITIALS() => "Initials",
220 SYMBOL() => "Symbol",
246 50 => "Ultracondensed",
247 63 => "Extracondensed",
249 87 => "Semicondensed",
251 113 => "Semiexpanded",
253 150 => "Extraexpanded",
254 200 => "Ultraexpanded",
262 "default" => "Proportional",
265 # Build reverse mappings, (not needed yet)
266 for my $txt (qw(ftypes weights slants widths spacings)) {
268 eval "\$map = \\%$txt";
269 for my $key (keys %{$map}) {
270 next if ($key !~ /^\d+$/);
271 my $value = lc($map->{$key});
272 $map->{"r"}->{$value} = $key;
279 my %collectedfonts = ();
281 otf => 0, # type 2, opentype CFF (Compact Font Format)
282 ttc => 1.1, # type 1 (True Type font Collection)
283 ttf => 1.2, # type 1 (True Type Font)
284 woff=> 1.3, # type 1 (Web Open Font Format)
285 t1 => 1.4, # type 1 (postscript)
286 pfb => 1.5, # type 1 (Printer Font Binary)
287 pfa => 1.6, # type 1 (Printer Font Ascii)
288 pfm => 2, # requires associated .pfb file
289 pcf => 5, # Bitmap (Packaged Collaboration Files)?
293 # list of regexes for known sans serif fonts
295 "value" => SANS, # Sans serif
296 "a" => qr/^a(030|becedario|bydos|haroni|rial|ndika|ngostura|nonymous|rab|roania|rimo|sap)/i,
297 "b" => qr/^b(aekmuk|ebas|erenika|eteckna|euron|lue)/i,
298 "c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|hivo|mu bright|omfortaa|omi[cx]|oolvetica|ortoba|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
299 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
300 "e" => qr/^(electron|engebrechtre)/i,
301 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
302 "g" => qr/^(gardiner|garuda|gfs ?neo|gillius|granada|graph|guanine|gunplay)/i,
303 "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
304 "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
305 "j" => qr/^(jara|jura)/i,
306 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kurier|kustom)/i,
307 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
308 "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,
309 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
310 "o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
311 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
312 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
313 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
314 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
315 "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
316 "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)|uni(kurd|space|versalis)|roob|rw ?classico)/i,
317 "v" => qr/^(veranda|vn ?urwclassico)/i,
318 "w" => qr/^(waree)/i,
319 "y" => qr/^(yanone)/i,
320 "z" => qr/^(zekton|zero)/i,
323 "value" => SCRIPT, # Script
324 "c" => qr/^(chancery)/i,
325 "d" => qr/^(dancing)/i,
326 "e" => qr/^(elegante)/i,
327 "j" => qr/^jsmath.?(rsfs)/i,
328 "k" => qr/^(kaushan|karumbi|kristi)/i,
329 "m" => qr/^(mathjax_script|miama)/i,
330 "n" => qr/^(nanum (brush|pen) script)/i,
331 "q" => qr/^qt(arabian|boulevard|brushstroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
332 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
333 "t" => qr/^typo ?script/i,
334 "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
338 "value" => FRAKTUR, # Fraktur
340 "j" => qr/^(jsmath.?euf)/i,
341 "m" => qr/^(missaali)/i,
342 "o" => qr/^(oldania)/i,
343 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london)scroll)/i,
344 "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
348 "value" => FANCY, # Fancy
349 "a" => qr/^a(bandoned|bberancy)/i,
350 "c" => qr/^(cretino)/i,
352 "f" => qr/^frederika/i,
353 "g" => qr/^(gfs.?theo)/i,
354 "k" => qr/^keter|kicking|kredit|kouzan|kerkis calligraphic/i,
355 "u" => qr/^ukij ?(saet|tiken)/i,
359 "value" => INITIALS, # Initials
360 "e" => qr/^(eb.?garamond.?init)/i,
361 "t" => qr/^typographer/i,
362 "y" => qr/^(yinit)/i,
366 "value" => SYMBOL, # Symbol
367 "a" => qr/^(academicons)/i,
368 "c" => qr/^(caladings|ccicons|chess|cmsy|cmex)/i,
369 "d" => qr/^(dingbats|drmsym|d05)/i,
370 "e" => qr/^(elusiveicons|emoji|esint|euterpe)/i,
371 "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
372 "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot|complutum).?classic))/i,
374 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
375 "m" => qr/^(marvosym|material|msam|msbm)/i,
376 "n" => qr/^(noto.*emoji)/i,
377 "o" => qr/^(octicons)/i,
379 "q" => qr/^(qtdingbits)/i,
381 "t" => qr/^(typicons|twemoji)/i,
382 "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
383 "w" => qr/^(webdings|wasy)/i,
386 if (open(FI, "$cmd |")) {
387 NXTLINE: while (my $l = <FI>) {
389 while ($l !~ /abcd$/) {
395 if ($l =~ /file=\"([^\"]+)\"/) {
397 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
398 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
399 print "Unhandled extension for file $file\n";
403 if (! defined($fontpriority{$fonttype})) {
404 print "Added extension $fonttype for file $file\n";
405 $fontpriority{$fonttype} = $nexttype;
410 if ($l =~ / lang=\"([^\"]+)\"/) {
411 my @ll = split(/\|/, $1);
413 $usedlangs{&convertlang($lx)} = 1;
417 for my $lang (@langs) {
418 next NXTLINE if (! defined($usedlangs{$lang}));
420 my $style = &getVal($l, "style", "stylelang", 1);
421 $style =~ s/^\\040//;
422 my $fullname = &getVal($l, "fn", "fnl");
423 my $postscriptname = "";
424 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
425 $postscriptname = $1;
427 my $family = &getVal($l, "family", "flang", 0);
428 my $fontname = &buildFontName($family, $style, $fullname, $postscriptname);
430 if (defined($options{NFontName})) {
431 for my $fn (@{$options{NFontName}}) {
432 next NXTLINE if ($fontname =~ /$fn/i);
435 if (defined($options{FontName})) {
436 for my $fn (@{$options{FontName}}) {
437 next NXTLINE if ($fontname !~ /$fn/i);
441 if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
442 if ($l =~ / charset=\"([^\"]+)\"/) {
443 my @list = split(/\s+/, $1);
445 my ($l, $h) = split('-', $e);
446 $h = $l if (! defined($h));
447 push(@charlist, [hex($l), hex($h)]);
450 if (defined($options{Contains})) {
451 for my $g (@{$options{Contains}}) {
452 next NXTLINE if (! contains($g, \@charlist));
455 if (defined($options{NContains})) {
456 for my $g (@{$options{NContains}}) {
457 # Ignore if ANY char exist in @charlist
458 for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
459 next NXTLINE if (contains([$i,$i], \@charlist));
466 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
467 my $properties = getproperties($l, $fontname, $style, \@errors);
468 if (defined($options{Property})) {
469 for my $pn (@{$options{Property}}) {
470 next NXTLINE if ($properties !~ /$pn/i);
473 if (defined($options{NProperty})) {
474 for my $pn (@{$options{NProperty}}) {
475 next NXTLINE if ($properties =~ /$pn/i);
478 if (exists($options{PrintProperties})) {
479 $props .= " ($properties)";
483 if (exists($options{PrintLangs})) {
484 $props .= '(' . join(',', sort keys %usedlangs) . ')';
486 if (exists($options{PrintCharset})) {
487 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
489 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
492 if ($l =~ / script=\"([^\"]+)\"/) {
493 @scripts = split(/\s+/, $1);
494 for my $ent (@scripts) {
495 $ent =~ s/^\s*otlayout://;
498 $scripts = join(',', @scripts);
500 if (exists($options{Math})) {
501 next NXTLINE if (! &ismathfont($fontname,\@scripts));
503 if (exists($options{PrintScripts})) {
504 $props .= "($scripts)";
506 if (!defined($scripts[0])) {
507 # No script defined in font, so check only $options{Scripts}
508 next NXTLINE if (defined($options{Scripts}));
511 if (defined($options{Scripts})) {
512 for my $s (@{$options{Scripts}}) {
513 next NXTLINE if ($scripts !~ /$s/i);
516 if (defined($options{NScripts})) {
517 for my $s (@{$options{NScripts}}) {
518 next NXTLINE if ($scripts =~ /$s/i);
524 if ($l =~ /foundry=\"([^\"]+)\"/) {
526 $foundry =~ s/^\s+//;
527 $foundry =~ s/\s+$//;
529 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
530 # Apparently not the first one, so add some info
531 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
532 if (defined($errors[0])) {
533 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
535 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
536 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info for file: " . $collectedfonts{$fontname}->{$foundry}->{file});
539 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info for file: $file");
544 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
546 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
547 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
548 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
553 for my $fontname (sort keys %collectedfonts) {
554 my @foundries = sort keys %{$collectedfonts{$fontname}};
555 my $printfoundries = 0;
556 if (defined($foundries[1])) {
559 for my $foundry (@foundries) {
560 if (exists($options{PrintWarnings})) {
561 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
565 my $fn = "Font : $fontname";
566 if ($printfoundries && ($foundry ne "")) {
567 $fn .= " \[$foundry\]";
570 print $collectedfonts{$fontname}->{$foundry}->{props};
571 if (exists($options{PrintFiles})) {
572 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
581 #################################################################################
585 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
586 my ($x, $y) = ($1, $3);
588 $ilang = lc($x) . '-' . lc($y);
599 my ($l, $islang, $txt, $rres) = @_;
601 if ($l =~ /$txt=\"([^\"]+)\"/) {
602 @res = split(',', $1);
605 $lg = &convertlang($lg);
614 my ($lang, $rlangs) = @_;
617 for (my $i = 0; defined($rlangs->[$i]); $i++) {
618 if ($rlangs->[$i] eq $lang) {
627 my ($l, $txtval, $txtlang, $combine) = @_;
630 &extractlist($l, 0, $txtval, \@values);
631 return("") if (! defined($values[0]));
632 &extractlist($l, 1, $txtlang, \@langs);
633 my $i = &getIndexes("en", \@langs);
636 if (defined($values[$k])) {
639 $res .= " $values[$k]";
646 if (length($values[$k]) > length($res)) {
652 return($values[0]) if ($res eq "");
656 sub getsinglevalue($$$)
658 my ($l, $txt, $rMap, $rget) = @_;
660 if ($l =~ / $txt=(\d+)/) {
662 # Search for nearest value to $val
663 if (defined($rMap->{$val})) {
664 return($rMap->{$val});
668 for my $key (keys %{$rMap}) {
669 next if ($key !~ /^\d+$/);
670 my $diff = abs($key - $val);
675 elsif ($diff == $minv) {
681 if (! defined($rMap->{$maxv})) {
682 print "ERROR2: txt=$txt, val=$val\n";
686 return($rMap->{$maxv} . "+$minv");
689 return($rMap->{$maxv} . "-$minv");
699 my ($txt, $val) = @_;
700 return("$txt($val)");
705 my ($fontname, $style) = @_;
707 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
710 elsif ($fontname =~ /gothic|dotum|gulim/i) {
711 if ($fontname =~ /bisrat gothic/i) {
718 elsif ($fontname =~ /^(jsmath.?)?bbold|msbm|^(ds(rom|serif|ss))/i) {
719 $resftype |= DOUBLESTROKE; # Double stroke (math font)
721 if ($fontname =~ /serif|times|mincho|batang/i) {
722 if ($fontname =~ /good times/i) {
723 $resftype |= SANS; # Sans Serif
726 if ($fontname =~ /initial(s|en)/i) {
727 $resftype |= INITIALS;
729 if ($fontname =~ /symbol/i) {
730 if ($fontname !~ /^symbola/i) {
734 # Now check for fonts without a hint in font name
735 if ($fontname =~ /^([a-z])/i) {
737 for my $rFonts (\%sansFonts, \%scriptFonts, \%fraktFonts, \%fancyFonts, \%initialFonts, \%symbolFonts) {
738 if (defined($rFonts->{$key})) {
739 if ($fontname =~ $rFonts->{$key}) {
740 $resftype |= $rFonts->{"value"};
745 if ("$fontname" =~ /^bpg/i) {
746 if ("$fontname" =~ /bpg (courier gpl|elite)/i) {
747 $resftype |= SERIF; # Serif
750 $resftype |= SANS; # Sans Serif
753 elsif ("$fontname" =~ /^dustismo/i) {
754 if ("$fontname" =~ /^dustismo roman/i) {
755 $resftype |= SERIF; # Serif
758 $resftype |= SANS; # Sans Serif
761 elsif ("$fontname" =~ /^go\b/i) {
762 if ("$fontname" =~ /^go mono/i) {
763 $resftype |= SERIF; # Serif
766 $resftype |= SANS; # Sans Serif
771 if ($resftype == 0) {
772 $resftype = $ftypes{default};
774 elsif ($resftype & SANS) {
777 for (my $i = 1; $i < 513; $i *= 2) {
778 if ($resftype & $i) {
779 push(@ft, $ftypes{$i});
782 return(join(',', @ft));
787 my ($fontname, $style) = @_;
789 for my $info ($style, $fontname) {
790 for my $key (keys %weights) {
791 next if ($key !~ /^\d+$/);
792 my $val = $weights{$key};
793 if ($info =~ /\b$val\b/i) {
803 my ($fontname, $style) = @_;
805 for my $key (keys %widths) {
806 next if ($key !~ /^\d+$/);
807 for my $info ($style, $fontname) {
808 if ($info =~ /\b$widths{$key}\b/i) {
809 return($widths{$key});
811 if ($info =~ /\bRegular\b/) {
812 if (!defined($result)) {
813 $result = $widths{100};
823 my ($fontname, $style) = @_;
824 for my $key (keys %slants) {
825 next if ($key !~ /^\d+$/);
826 if ($style =~ /\b$slants{$key}\b/i) {
827 return($slants{$key});
835 my ($fontname, $style) = @_;
836 for my $key (keys %spacings) {
837 next if ($key !~ /^\d+$/);
838 if ($style =~ /\b$spacings{$key}\b/i) {
839 return($spacings{$key});
842 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
843 return($spacings{100}); # Mono
852 my ($fontname, $rCapability) = @_;
854 return 1 if ($fontname =~ /math/i);
855 for my $cap (@{$rCapability}) {
856 return 1 if ($cap eq "math");
861 sub getproperties($$$$)
863 my ($l, $fontname, $style, $rerrors) = @_;
864 my $newstyle = &correctstyle($style);
865 my $newfam = &correctstyle($fontname);
868 for my $txt (qw(ftype weight width slant spacing)) {
870 eval("\$map = " . '\%' . $txt . 's');
871 eval('$rget = \&' . "get$txt");
872 my $val2 = getsinglevalue($l, $txt, $map);
873 my $val1 = $rget->($newfam, $newstyle);
875 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
876 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/)){
877 # style overrides weight and slant
878 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
881 elsif ($newfam =~ /$val1/) {
882 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
886 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
890 elsif (! defined($val2)) {
897 push(@properties, &addTxt($txt,$val));
900 if (defined($map->{"default"})) {
901 push(@properties, &addTxt($txt,$map->{"default"}));
904 push(@{$rerrors}, "Undefined value for $txt");
908 return(join(' ', @properties));
914 $style =~ s/^\\040//;
915 $style =~ s/^\s*\d+\s*//;
916 $style =~ s/\s*\d+$//;
917 $style =~ s/italic/ Italic/i;
918 $style =~ s/oblique/ Oblique/i;
919 $style =~ s/[\-_]/ /g;
920 $style =~ s/\breg\b/Regular/i;
921 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
922 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
923 $style =~ s/medium/Medium /i;
924 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
925 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
926 $style =~ s/\bmed\b/Medium /i;
927 $style =~ s/\bdemi\b/SemiBold/i;
928 $style =~ s/\bex(pd|t)\b/Expanded/i;
929 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
930 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
931 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
932 $style =~ s/[sd]emi ?light/SemiLight/i;
933 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
934 $style =~ s/light/Light /i;
935 $style =~ s/\blt\b/Light /i;
936 $style =~ s/(ultra|extra)(light|lt)/ExtraLight /i;
937 $style =~ s/\bheavy\b/Extrabold/i;
938 $style =~ s/\bhairline\b/Extralight/i;
939 $style =~ s/\bcond\b/Condensed/i;
940 $style =~ s/(roman)?slanted/ Italic/i;
941 $style =~ s/\bslant\b/Italic/i;
942 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
943 $style =~ s/w3 mono/Dual/i;
944 $style =~ s/Regul[ea]r/Regular/i;
945 $style =~ s/Megablack/ExtraBlack/i;
950 # return list of unicode values of the input string
951 #Allow input of intervals (e.g. 'a-z')
952 sub decimalUnicode($)
956 # Convert to unicode chars first
957 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
958 my ($prev, $d, $post) = ($1, $2, $3);
959 if ($d =~ /^0?x(.+)$/) {
962 my $chr = encode('utf-8', chr($d));
963 $a = $prev . $chr . $post;
965 # $a is now a string of unicode chars
966 my $u = decode('utf-8', $a);
967 my @a = split(//, $u);
971 if ($x eq '-') { # Interval
975 if ($interval && defined($start)) {
976 if (ord($x) < $start) {
977 for (my $i = $start - 1; $i >= ord($x); $i--) {
982 for (my $i = $start + 1; $i <= ord($x); $i++) {
998 # check if the glyph-values in interval @{$ri} are contained
999 # in one of the (sorted) intervals
1003 # ...re0..........re1...
1004 # ......start..end......
1005 my ($ri, $rList) = @_;
1006 my $start = $ri->[0];
1009 for my $re (@{$rList}) {
1010 next if ($re->[1] < $start);
1011 # now we found a possible matching interval
1012 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1018 sub sprintIntervalls($)
1022 for my $rE (@{$rList}) {
1023 if ($rE->[0] != $rE->[1]) {
1024 push(@out, $rE->[0] . '-' . $rE->[1]);
1027 push(@out, $rE->[0]);
1030 return join(',', @out);
1033 sub buildFontName($$$$)
1035 my ($family, $style, $fullname, $postscriptname) = @_;
1038 $style =~ s/\\040//;
1039 $family =~ s/\\040/\-/;
1040 $family =~ s/\bcond\b/Condensed/i;
1041 $family =~ s/\bblk\b/Black/i;
1042 $family =~ s/\bsembd\b/SemiBold/i;
1043 $family =~ s/\bsemcond\b/SemiCondensed/i;
1044 $family =~ s/\bextcond\b/ExtraCondensed/i;
1045 $family =~ s/\bextbd\b/ExtraBold/i;
1046 $family =~ s/\bextlt\b/ExtraLight/i;
1047 $style =~ s/\bextra\-light\b/ExtraLight/i;
1048 $style =~ s/\bbol\b/Bold/i;
1049 $family =~ s/\bmed\b/Medium/i;
1050 if ($family =~ /powerline/i) {
1053 $family =~ s/^([A-Z]+[a-z]+)([A-Z][a-z]+)\b/$1 $2/;
1054 my @style = split(' ', $style);
1055 for my $st (@style) {
1057 if ($family !~ s/$st/$st/i) {
1061 # check if $st in $family starts with ' '
1062 $family =~ s/(\w)$st/$1 $st/i;
1065 $postscriptname =~ s/[- ]?Regular$//;
1066 if ($fullname =~ /^(font)?\d+/) {
1069 if (length($fullname) <= length($family)) {
1073 $result = $fullname;