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)?
294 # some extra serif fonts
296 "g" => qr/^gfs ?(didot)/i,
298 # list of regexes for known sans serif fonts
300 "value" => SANS, # Sans serif
301 "a" => qr/^a(030|bydos|haroni|e?rial|ndika|ngostura|nonymous|rab|roania|rimo|sap|e almothnna|egean|egyptus|l (arabiya|battar|hor|manzomah|yarmook)|lmonte|natolian|ndale|nglepoise|njali|xaxa)/i,
302 "b" => qr/^b(abel ?stone ?modern|aekmuk|alker|altar|andal|angwool|arbatrick|aveuse|dxsfm|ebas|erenika|eteckna|euron|iometric|iting|lue|m ?hanna)/i,
303 "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,
304 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
305 "e" => qr/^(electron|engebrechtre)/i,
306 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
307 "g" => qr/^(gardiner|garuda|gfs ?neo|gillius|granada|graph|guanine|gunplay)/i,
308 "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
309 "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
310 "j" => qr/^(jara|jura)/i,
311 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kurier|kustom)/i,
312 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
313 "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,
314 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
315 "o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
316 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
317 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
318 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
319 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
320 "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
321 "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,
322 "v" => qr/^(veranda|vn ?urwclassico)/i,
323 "w" => qr/^(waree)/i,
324 "y" => qr/^(yanone)/i,
325 "z" => qr/^(zekton|zero)/i,
328 "value" => SCRIPT, # Script
329 "a" => qr/^a(becedario|ir ?cut|ugie|uriocus ?kalligraph)/i,
330 "b" => qr/^b(reip|rush ?script)/i,
331 "c" => qr/^(chancery)/i,
332 "d" => qr/^(dancing)/i,
333 "e" => qr/^(elegante)/i,
334 "f" => qr/^femkeklaver/i,
335 "j" => qr/^jsmath.?(rsfs)/i,
336 "k" => qr/^(kaushan|karumbi|kristi)/i,
337 "m" => qr/^(mathjax_script|miama)/i,
338 "n" => qr/^(nanum (brush|pen) script)/i,
340 "q" => qr/^qt(arabian|boulevard|brush ?stroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
341 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
342 "t" => qr/^typo ?script/i,
343 "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
347 "value" => FRAKTUR, # Fraktur
348 "b" => qr/^boondox ?fraktur/i,
350 "j" => qr/^(jsmath.?euf)/i,
351 "m" => qr/^(missaali)/i,
352 "o" => qr/^(oldania)/i,
353 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london)scroll)/i,
354 "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
358 "value" => FANCY, # Fancy
359 "a" => qr/^a(bandoned|bberancy|driator|irmole|lmonte (snow|woodgrain)|nalecta|ni|nklepants|nn ?stone|oyagi|rt ?nouveau ?caps|stron|xaxa)/i,
360 "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,
361 "c" => qr/^c(retino|msy)/i,
363 "e" => qr/^electorate/i,
364 "f" => qr/^frederika/i,
365 "g" => qr/^(gfs.?theo)/i,
366 "j" => qr/^jsmath.cmsy/i,
367 "k" => qr/^keter|kicking|kredit|kouzan|kerkis calligraphic/i,
369 "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
370 "v" => qr/^vectroid/i,
374 "value" => INITIALS, # Initials
375 "e" => qr/^(eb.?garamond.?init)/i,
376 "t" => qr/^typographer/i,
377 "y" => qr/^(yinit)/i,
381 "value" => SYMBOL, # Symbol
382 "a" => qr/^a(cademicons|lblant|lianna|mar|nka|rb?\d|rchaic|rrow|rs|rt[mt]|ssy(rb\d+)?\b|miri ?quran|mit\b)/i,
383 "b" => qr/^b(aby ?jeepers|bding|euron|guq|lex|lsy|oondox ?upr|ullets|urma)/i,
384 "c" => qr/^(caladings|ccicons|chess|cmsy|cmex)/i,
385 "d" => qr/^(dingbats|drmsym|d05)/i,
386 "e" => qr/^e(lusiveicons|mmentaler|moji|sint|uterpe)/i,
387 "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
388 "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot).?classic|complutum))/i,
390 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
391 "l" => qr/^l(cmsy|msam)/i,
392 "m" => qr/^(marvosym|material|msam|msbm)/i,
393 "n" => qr/^(noto.*(emoji|brahmi))/i,
394 "o" => qr/^(octicons)/i,
396 "q" => qr/^(qtding ?bits)/i,
397 "s" => qr/^s(kak|tmary|s?msam)/i,
398 "t" => qr/^(typicons|twemoji)/i,
399 "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
400 "w" => qr/^w(ebdings|asy|elfare ?brat)/i,
403 if (open(FI, "$cmd |")) {
404 NXTLINE: while (my $l = <FI>) {
406 while ($l !~ /abcd$/) {
412 if ($l =~ /file=\"([^\"]+)\"/) {
414 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
415 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
416 print "Unhandled extension for file $file\n";
420 if (! defined($fontpriority{$fonttype})) {
421 print "Added extension $fonttype for file $file\n";
422 $fontpriority{$fonttype} = $nexttype;
427 if ($l =~ / lang=\"([^\"]+)\"/) {
428 my @ll = split(/\|/, $1);
430 $usedlangs{&convertlang($lx)} = 1;
434 for my $lang (@langs) {
435 next NXTLINE if (! defined($usedlangs{$lang}));
437 my $style = &getVal($l, "style", "stylelang", 1);
438 $style =~ s/^\\040//;
439 my $fullname = &getVal($l, "fn", "fnl");
440 my $postscriptname = "";
441 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
442 $postscriptname = $1;
444 my $family = &getVal($l, "family", "flang", 0);
445 my $fontname = &buildFontName($family, $style, $fullname, $postscriptname);
447 if (defined($options{NFontName})) {
448 for my $fn (@{$options{NFontName}}) {
449 next NXTLINE if ($fontname =~ /$fn/i);
452 if (defined($options{FontName})) {
453 for my $fn (@{$options{FontName}}) {
454 next NXTLINE if ($fontname !~ /$fn/i);
458 if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
459 if ($l =~ / charset=\"([^\"]+)\"/) {
460 my @list = split(/\s+/, $1);
462 my ($l, $h) = split('-', $e);
463 $h = $l if (! defined($h));
464 push(@charlist, [hex($l), hex($h)]);
467 if (defined($options{Contains})) {
468 for my $g (@{$options{Contains}}) {
469 next NXTLINE if (! contains($g, \@charlist));
472 if (defined($options{NContains})) {
473 for my $g (@{$options{NContains}}) {
474 # Ignore if ANY char exist in @charlist
475 for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
476 next NXTLINE if (contains([$i,$i], \@charlist));
483 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
484 my $properties = getproperties($l, $fontname, $style, \@errors);
485 if (defined($options{Property})) {
486 for my $pn (@{$options{Property}}) {
487 next NXTLINE if ($properties !~ /$pn/i);
490 if (defined($options{NProperty})) {
491 for my $pn (@{$options{NProperty}}) {
492 next NXTLINE if ($properties =~ /$pn/i);
495 if (exists($options{PrintProperties})) {
496 $props .= " ($properties)";
500 if (exists($options{PrintLangs})) {
501 $props .= '(' . join(',', sort keys %usedlangs) . ')';
503 if (exists($options{PrintCharset})) {
504 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
506 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
509 if ($l =~ / script=\"([^\"]+)\"/) {
510 @scripts = split(/\s+/, $1);
511 for my $ent (@scripts) {
512 $ent =~ s/^\s*otlayout://;
515 $scripts = join(',', @scripts);
517 if (exists($options{Math})) {
518 next NXTLINE if (! &ismathfont($fontname,\@scripts));
520 if (exists($options{PrintScripts})) {
521 $props .= "($scripts)";
523 if (!defined($scripts[0])) {
524 # No script defined in font, so check only $options{Scripts}
525 next NXTLINE if (defined($options{Scripts}));
528 if (defined($options{Scripts})) {
529 for my $s (@{$options{Scripts}}) {
530 next NXTLINE if ($scripts !~ /$s/i);
533 if (defined($options{NScripts})) {
534 for my $s (@{$options{NScripts}}) {
535 next NXTLINE if ($scripts =~ /$s/i);
541 if ($l =~ /foundry=\"([^\"]+)\"/) {
543 $foundry =~ s/^\s+//;
544 $foundry =~ s/\s+$//;
546 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
547 # Apparently not the first one, so add some info
548 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
549 if (defined($errors[0])) {
550 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
552 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
553 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info for file: " . $collectedfonts{$fontname}->{$foundry}->{file});
556 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info for file: $file");
561 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
563 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
564 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
565 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
570 for my $fontname (sort keys %collectedfonts) {
571 my @foundries = sort keys %{$collectedfonts{$fontname}};
572 my $printfoundries = 0;
573 if (defined($foundries[1])) {
576 for my $foundry (@foundries) {
577 if (exists($options{PrintWarnings})) {
578 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
582 my $fn = "Font : $fontname";
583 if ($printfoundries && ($foundry ne "")) {
584 $fn .= " \[$foundry\]";
587 print $collectedfonts{$fontname}->{$foundry}->{props};
588 if (exists($options{PrintFiles})) {
589 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
598 #################################################################################
602 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
603 my ($x, $y) = ($1, $3);
605 $ilang = lc($x) . '-' . lc($y);
616 my ($l, $islang, $txt, $rres) = @_;
618 if ($l =~ /$txt=\"([^\"]+)\"/) {
619 @res = split(',', $1);
622 $lg = &convertlang($lg);
631 my ($lang, $rlangs) = @_;
634 for (my $i = 0; defined($rlangs->[$i]); $i++) {
635 if ($rlangs->[$i] eq $lang) {
644 my ($l, $txtval, $txtlang, $combine) = @_;
647 &extractlist($l, 0, $txtval, \@values);
648 return("") if (! defined($values[0]));
649 &extractlist($l, 1, $txtlang, \@langs);
650 my $i = &getIndexes("en", \@langs);
653 if (defined($values[$k])) {
656 $res .= " $values[$k]";
663 if (length($values[$k]) > length($res)) {
669 return($values[0]) if ($res eq "");
673 sub getsinglevalue($$$)
675 my ($l, $txt, $rMap, $rget) = @_;
677 if ($l =~ / $txt=(\d+)/) {
679 # Search for nearest value to $val
680 if (defined($rMap->{$val})) {
681 return($rMap->{$val});
685 for my $key (keys %{$rMap}) {
686 next if ($key !~ /^\d+$/);
687 my $diff = abs($key - $val);
692 elsif ($diff == $minv) {
698 if (! defined($rMap->{$maxv})) {
699 print "ERROR2: txt=$txt, val=$val\n";
703 return($rMap->{$maxv} . "+$minv");
706 return($rMap->{$maxv} . "-$minv");
716 my ($txt, $val) = @_;
717 return("$txt($val)");
722 my ($fontname, $style) = @_;
724 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
727 elsif ($fontname =~ /gothic|dotum|gulim/i) {
728 if ($fontname =~ /bisrat gothic/i) {
735 elsif ($fontname =~ /^(jsmath.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
736 $resftype |= DOUBLESTROKE; # Double stroke (math font)
738 if ($fontname =~ /serif|times|mincho|batang/i) {
739 if ($fontname =~ /good times/i) {
740 $resftype |= SERIF; # Serif
743 if ($fontname =~ /initial(s|en)/i) {
744 $resftype |= INITIALS;
746 if ($fontname =~ /participants/i) {
747 $resftype |= SANS|FANCY;
749 if ($fontname =~ /symbol/i) {
750 if ($fontname !~ /^symbola/i) {
754 # Now check for fonts without a hint in font name
755 if ($fontname =~ /^([a-z])/i) {
757 # check the mutual exclusive first
758 for my $rFonts (\%fraktFonts, \%scriptFonts, \%sansFonts, \%serifFonts) {
759 if (defined($rFonts->{$key})) {
760 if ($fontname =~ $rFonts->{$key}) {
761 $resftype |= $rFonts->{"value"};
766 for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts) {
767 if (defined($rFonts->{$key})) {
768 if ($fontname =~ $rFonts->{$key}) {
769 $resftype |= $rFonts->{"value"};
774 if ("$fontname" =~ /^bpg/i) {
775 if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
776 $resftype |= SERIF; # Serif
779 $resftype |= SANS; # Sans Serif
782 elsif ("$fontname" =~ /^dustismo/i) {
783 if ("$fontname" =~ /^dustismo roman/i) {
784 $resftype |= SERIF; # Serif
787 $resftype |= SANS; # Sans Serif
790 elsif ("$fontname" =~ /^go\b/i) {
791 if ("$fontname" =~ /^go mono/i) {
792 $resftype |= SERIF; # Serif
795 $resftype |= SANS; # Sans Serif
800 if ($resftype == 0) {
801 $resftype = $ftypes{default};
804 # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
805 if ($resftype & FRAKTUR) {
806 $resftype &= ~(SANS|SERIF|SCRIPT);
808 elsif ($resftype & SCRIPT) {
809 $resftype &= ~(SANS|SERIF);
811 elsif ($resftype & SANS) {
815 for (my $i = 1; $i < 513; $i *= 2) {
816 if ($resftype & $i) {
817 push(@ft, $ftypes{$i});
820 return(join(',', @ft));
825 my ($fontname, $style) = @_;
827 for my $info ($style, $fontname) {
828 for my $key (keys %weights) {
829 next if ($key !~ /^\d+$/);
830 my $val = $weights{$key};
831 if ($info =~ /\b$val\b/i) {
841 my ($fontname, $style) = @_;
843 for my $key (keys %widths) {
844 next if ($key !~ /^\d+$/);
845 for my $info ($style, $fontname) {
846 if ($info =~ /\b$widths{$key}\b/i) {
847 return($widths{$key});
849 if ($info =~ /\bRegular\b/) {
850 if (!defined($result)) {
851 $result = $widths{100};
861 my ($fontname, $style) = @_;
862 for my $key (keys %slants) {
863 next if ($key !~ /^\d+$/);
864 if ($style =~ /\b$slants{$key}\b/i) {
865 return($slants{$key});
873 my ($fontname, $style) = @_;
874 for my $key (keys %spacings) {
875 next if ($key !~ /^\d+$/);
876 if ($style =~ /\b$spacings{$key}\b/i) {
877 return($spacings{$key});
880 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
881 return($spacings{100}); # Mono
890 my ($fontname, $rCapability) = @_;
892 return 1 if ($fontname =~ /math/i);
893 for my $cap (@{$rCapability}) {
894 return 1 if ($cap eq "math");
899 sub getproperties($$$$)
901 my ($l, $fontname, $style, $rerrors) = @_;
902 my $newstyle = &correctstyle($style);
903 my $newfam = &correctstyle($fontname);
906 for my $txt (qw(ftype weight width slant spacing)) {
908 eval("\$map = " . '\%' . $txt . 's');
909 eval('$rget = \&' . "get$txt");
910 my $val2 = getsinglevalue($l, $txt, $map);
911 my $val1 = $rget->($newfam, $newstyle);
913 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
914 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/)){
915 # style overrides weight and slant
916 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
919 elsif ($newfam =~ /$val1/) {
920 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
924 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
928 elsif (! defined($val2)) {
935 push(@properties, &addTxt($txt,$val));
938 if (defined($map->{"default"})) {
939 push(@properties, &addTxt($txt,$map->{"default"}));
942 push(@{$rerrors}, "Undefined value for $txt");
946 return(join(' ', @properties));
952 $style =~ s/^\\040//;
953 $style =~ s/^\s*\d+\s*//;
954 $style =~ s/\s*\d+$//;
955 $style =~ s/italic/ Italic/i;
956 $style =~ s/oblique/ Oblique/i;
957 $style =~ s/[\-_]/ /g;
958 $style =~ s/\breg\b/Regular/i;
959 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
960 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
961 $style =~ s/medium/Medium /i;
962 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
963 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
964 $style =~ s/\bmed\b/Medium /i;
965 $style =~ s/\bdemi\b/SemiBold/i;
966 $style =~ s/\bex(pd|t)\b/Expanded/i;
967 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
968 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
969 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
970 $style =~ s/[sd]emi ?light/SemiLight/i;
971 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
972 $style =~ s/light/Light /i;
973 $style =~ s/\blt\b/Light /i;
974 $style =~ s/(ultra|extra)(light|lt)/ExtraLight /i;
975 $style =~ s/\bheavy\b/Extrabold/i;
976 $style =~ s/\bhairline\b/Extralight/i;
977 $style =~ s/\bcond\b/Condensed/i;
978 $style =~ s/(roman)?slanted/ Italic/i;
979 $style =~ s/\bslant\b/Italic/i;
980 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
981 $style =~ s/w3 mono/Dual/i;
982 $style =~ s/Regul[ea]r/Regular/i;
983 $style =~ s/Megablack/ExtraBlack/i;
988 # return list of unicode values of the input string
989 #Allow input of intervals (e.g. 'a-z')
990 sub decimalUnicode($)
994 # Convert to unicode chars first
995 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
996 my ($prev, $d, $post) = ($1, $2, $3);
997 if ($d =~ /^0?x(.+)$/) {
1000 my $chr = encode('utf-8', chr($d));
1001 $a = $prev . $chr . $post;
1003 # $a is now a string of unicode chars
1004 my $u = decode('utf-8', $a);
1005 my @a = split(//, $u);
1009 if ($x eq '-') { # Interval
1013 if ($interval && defined($start)) {
1014 if (ord($x) < $start) {
1015 for (my $i = $start - 1; $i >= ord($x); $i--) {
1020 for (my $i = $start + 1; $i <= ord($x); $i++) {
1036 # check if the glyph-values in interval @{$ri} are contained
1037 # in one of the (sorted) intervals
1041 # ...re0..........re1...
1042 # ......start..end......
1043 my ($ri, $rList) = @_;
1044 my $start = $ri->[0];
1047 for my $re (@{$rList}) {
1048 next if ($re->[1] < $start);
1049 # now we found a possible matching interval
1050 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1056 sub sprintIntervalls($)
1060 for my $rE (@{$rList}) {
1061 if ($rE->[0] != $rE->[1]) {
1062 push(@out, $rE->[0] . '-' . $rE->[1]);
1065 push(@out, $rE->[0]);
1068 return join(',', @out);
1071 sub buildFontName($$$$)
1073 my ($family, $style, $fullname, $postscriptname) = @_;
1076 $style =~ s/\\040//;
1077 $family =~ s/\\040/\-/;
1078 $family =~ s/\bcond\b/Condensed/i;
1079 $family =~ s/\bblk\b/Black/i;
1080 $family =~ s/\bsembd\b/SemiBold/i;
1081 $family =~ s/\bsemcond\b/SemiCondensed/i;
1082 $family =~ s/\bextcond\b/ExtraCondensed/i;
1083 $family =~ s/\bextbd\b/ExtraBold/i;
1084 $family =~ s/\bextlt\b/ExtraLight/i;
1085 $style =~ s/\bextra\-light\b/ExtraLight/i;
1086 $style =~ s/\bbol\b/Bold/i;
1087 $family =~ s/\bmed\b/Medium/i;
1088 $family =~ s/^([A-Z]+[a-z]+)([A-Z][a-z]+)\b/$1 $2/;
1089 my @style = split(' ', $style);
1090 for my $st (@style) {
1092 if ($family !~ s/$st/$st/i) {
1096 # check if $st in $family starts with ' '
1097 $family =~ s/(\w)$st/$1 $st/i;
1100 $postscriptname =~ s/[- ]?Regular$//;
1101 if ($fullname =~ /^(font)?\d+/) {
1104 if (length($fullname) <= length($family)) {
1108 $result = $fullname;