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/[\/\\]?[^\/\\]+$//;
33 my $lyxfontsdir = $INC[0];
34 $lyxfontsdir =~ s/[\/\\]?[^\/\\]+$//;
35 $lyxfontsdir =~ s/[\/\\]?[^\/\\]+$//;
36 $lyxfontsdir .= "/lib/fonts";
54 # for UseProperty (UP)
55 UPPROPERTY => 1, # select
56 UPNPROPERTY => 2, # deselect
57 UPPPROPERTIES => 4, # print
58 UPWPROPERTIES => 8, # write to a file
60 # for UseCharsets (UC)
61 UCCONTAINS => 1, # select
62 UCNCONTAINS => 2, # deselect
63 UCPCONTAINS => 4, # print
66 USSCRIPT => 1, # select
67 USNSCRIPT => 2, # deselect
68 USMSCRIPT => 4, # math
69 USPSCRIPT => 8, # print
70 USWSCRIPT => 16, # write to a file
73 # These will be set according to options
74 my $iproperty = 0; # info for Use Properties
75 my $icontains = 0; # info for Use Charsets
76 my $iscript = 0; # info for Use Scripts
79 sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
81 sub getVal($$$$); # my ($l, $txtval, $txtlang, $combine) = @_;
82 sub getproperties($$$$);
85 sub decimalUnicode($);
87 sub sprintIntervalls($);
88 sub buildFontName($$);
89 sub splitatlU($); # split text at change from lower case to upper case
92 # Following fields for a parameter can be defined:
93 # fieldname: Name of entry in %options
94 # type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
95 # alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
96 # listsep: Separator for multiple data
97 # comment: Parameter description
99 # help + verbose already handled in 'GetOptions'
101 {fieldname => "FontName", listsep => ',',
102 type => "=s", alias => ["name"],
103 comment => "Select font-names matching these (comma separated) regexes"},],
105 {fieldname => "NFontName",
106 type => "=s", listsep => ',',
107 comment => "Select font-names NOT matching these (comma separated) regexes"},],
109 {fieldname => "Property",
110 type => "=s", listsep => ',',
111 comment => "Select fonts with properties matching these (comma separated) regexes"},],
113 {fieldname => "NProperty",
114 type => "=s", listsep => ',',
115 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
117 {fieldname => "Scripts",
118 type => "=s", listsep => ',',
119 comment => "Select fonts with scripts matching these (comma separated) regexes"},],
121 {fieldname => "NScripts",
122 type => "=s", listsep => ',',
123 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
125 {fieldname => "Math",
126 comment => "Select fonts probably containing math glyphs"},],
128 {fieldname => "Contains", alias => ["contains"],
129 type => "=s", listsep => ',',
130 comment => "Select fonts containing all these (possibly comma separated) glyphs",
131 comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
133 {fieldname => "NContains",
134 type => "=s", listsep => ',',
135 comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
136 comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
138 {fieldname => "Lang",
139 type => "=s", alias=>["lang"],
140 comment => "Comma separated list of desired languages"},],
142 {fieldname => "PrintCharset", alias => ["printcharset"],
143 comment => "Print intervals of supported unicode character values"},],
145 {fieldname => "PrintLangs", alias => ["printlangs"],
146 comment => "Print supported languages"},],
148 {fieldname => "PrintProperties", alias => ["printproperties"],
149 comment => "Print properties from weight, slant and width"},],
151 {fieldname => "PrintScripts", alias => ["printscripts"],
152 comment => "Print supported scripts"},],
154 {fieldname => "PrintFiles", alias => ["printfiles"],
155 comment => "Print font file names"},],
157 {fieldname => "PrintWarnings",
158 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
160 {fieldname => "Write",
161 type => "=s", alias => ["writefile"],
162 comment => "Write to a file for later use"},],
164 my %options = %{&handleOptions(\@optionsDef)};
166 $options{Lang} = "" if (! defined($options{Lang}));
168 #############################################################
170 "Cond" => "Condensed",
171 "Expd" => "Expanded",
178 my @langs = split(',', $options{Lang});
179 for my $lg (@langs) {
180 $lg = &convertlang($lg);
183 $iproperty |= UPPROPERTY if (defined($options{Property}));
184 $iproperty |= UPNPROPERTY if (defined($options{NProperty}));
185 $iproperty |= UPPPROPERTIES if (exists($options{PrintProperties}));
187 $icontains |= UCCONTAINS if (defined($options{Contains}));
188 $icontains |= UCNCONTAINS if (defined($options{NContains}));
189 $icontains |= UCPCONTAINS if (exists($options{PrintCharset}));
191 $iscript |= USSCRIPT if (defined($options{Scripts}));
192 $iscript |= USNSCRIPT if (defined($options{NScripts}));
193 $iscript |= USMSCRIPT if (exists($options{Math}));
194 $iscript |= USPSCRIPT if (exists($options{PrintScripts}));
196 if (defined($options{Write})) {
197 if (! open(INFOS, '>', $options{Write})) {
198 die("Could not open file $options{Write} for write");
200 $iproperty |= UPWPROPERTIES;
202 # $iscript |= USWSCRIPT;
205 for my $charFld ("Contains", "NContains") {
206 if (defined($options{$charFld})) {
207 my %glyphs = (); # To ignore duplicates
208 for my $a1 (@{$options{$charFld}}) {
209 for my $e (decimalUnicode($a1)) {
214 my @glyphs = sort {$a <=> $b;} keys %glyphs;
216 # $options{$charFld} no longer needed, so use it for unicode-point intervalls
217 $options{$charFld} = [];
218 my ($first, $last) = (undef, undef);
219 for my $i (@glyphs) {
220 if (! defined($last)) {
229 push(@{$options{$charFld}}, [$first, $last]);
233 if (defined($last)) {
234 push(@{$options{$charFld}}, [$first, $last]);
236 if (exists($options{verbose})) {
237 if ($charFld eq "Contains") {
238 print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
241 print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
247 for my $fn ("FontName", "NFontName") {
248 if (defined($options{$fn})) {
249 # split each entry and make a compiled regex
250 # Allow space between all characters
251 for my $e (@{$options{$fn}}) {
252 if ($e =~ /(\^|\\|\||\[|\]|\(|\)|\*|\+|\?)/) {
253 # already regex, don't manipulate
257 my $u = decode('utf-8', $e);
258 my $fill = decode('utf-8', "\\s?");
259 my @u = split(//, $u);
260 my $ud = join($fill, @u);
261 my $e1 = encode('utf-8', $ud);
272 if (defined($langs[0])) {
273 $langs = " :lang=" . join(',', @langs) . " ";
276 my $format = "foundry=\"%{foundry}\"" .
277 " postscriptname=\"%{postscriptname}\"" .
278 " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
279 " family=\"%{family}\" flang=\"%{familylang}\" " .
280 " style=\"%{style}\" stylelang=\"%{stylelang}\"";
283 $format .= " script=\"%{capability}\"";
285 if (exists($options{PrintLangs}) || defined($langs[0])) {
286 $format .= " lang=\"%{lang}\"";
289 $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
292 $format .= " charset=\"%{charset}\"";
294 $format .= " file=\"%{file}\" abcd\\n";
295 $cmd .= $langs . " -f '$format'";
298 # Now Add also lyx fonts to be examinated
299 if (opendir(DI, "$lyxfontsdir")) {
300 while (my $l = readdir(DI)) {
302 if ($l =~ /\.ttf$/) {
303 my $file = "$lyxfontsdir/$l";
304 push(@cmds, "fc-query$langs -f '$format' '$file'");
314 # using '()' to prevent the initializer to take
315 # the key as a string. (Constants in perl _are_ functions without argument)
318 SCRIPT() => "Script",
319 FRAKTUR() => "Fraktur",
320 DOUBLESTROKE() => "DoubleStroke",
322 INITIALS() => "Initials",
323 SYMBOL() => "Symbol",
324 SMALLCAP() => "SmallCap",
350 50 => "Ultracondensed",
351 63 => "Extracondensed",
353 87 => "Semicondensed",
355 113 => "Semiexpanded",
357 150 => "Extraexpanded",
358 200 => "Ultraexpanded",
366 "default" => "Proportional",
369 # Build reverse mappings, (not needed yet)
370 for my $txt (qw(ftypes weights slants widths spacings)) {
372 eval "\$map = \\%$txt";
373 for my $key (keys %{$map}) {
374 next if ($key !~ /^\d+$/);
375 my $value = lc($map->{$key});
376 $map->{"r"}->{$value} = $key;
383 my %collectedfonts = ();
385 otf => 0, # type 2, opentype CFF (Compact Font Format)
386 ttc => 1.1, # type 1 (True Type font Collection)
387 ttf => 1.2, # type 1 (True Type Font)
388 woff=> 1.3, # type 1 (Web Open Font Format)
389 t1 => 1.4, # type 1 (postscript)
390 pfb => 1.5, # type 1 (Printer Font Binary)
391 pfa => 1.6, # type 1 (Printer Font Ascii)
392 pfm => 2, # requires associated .pfb file
393 pcf => 5, # Bitmap (Packaged Collaboration Files)?
398 # some extra serif fonts
400 "g" => qr/^gfs ?(didot)/i,
402 # list of regexes for known sans serif fonts
404 "value" => SANS, # Sans serif
405 "a" => qr/^a(030|bydos|haroni|e?rial|ndika|ngostura|nonymous|rab|roania|rimo|rundina|sap|e almothnna|egean|egyptus|l (arabiya|battar|hor|manzomah|yarmook)|lmonte|natolian|ndale|nglepoise|njali|xaxa)/i,
406 "b" => qr/^b(abel ?stone ?modern|aekmuk|alker|altar|andal|angwool|arbatrick|aveuse|old|dxsfm|ebas|erenika|eteckna|euron|iometric|iting|lue|m ?hanna)/i,
407 "c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|harles|hilanka|hinese ?rocks|hivo|mu bright|omfortaa|omi[cx]|omputer ?(bold|(modern ?(bright ?((semi)?bold|math|oblique|roman|italic))))|oolvetica|ortoba|ountries|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
408 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
409 "e" => qr/^(electron|engebrechtre)/i,
410 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
411 "g" => qr/^g(ardiner|aruda|fs ?neo|illius|ood ?times|ranada|raph|uanine|unplay)/i,
412 "h" => qr/^(hack|hani|haramain|harano.*gothic|harmattan|hor\b)/i,
413 "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
414 "j" => qr/^j(ara|ura|s ?math.?bbold)/i,
415 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kp ?mono|kurier|kustom)/i,
416 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation ?mono|ibre franklin|ibris|inux biolinum|obster|ogix|ohit ?(devana|telugu)|oma)/i,
417 "m" => qr/^m(\+ |anchu|anjari|arcellus|ashq|eera|etal|igmix|igu|ikachan|intspirit|iriam ?clm|isaki|itra ?mono|ona|onlam|ono(fonto|id|isome|noki)|ontserrat|otoyal|ukti|usica)/i,
418 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice|noto ?mono)/i,
419 "o" => qr/^(ocr|okolaks|open ?dyslexic|ostorah|ouhud|over|oxygen)/i,
420 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
421 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
422 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
423 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
424 "t" => qr/^(tarablus|teen|tex ?gyre ?(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
425 "u" => qr/^u(buntu|kij (bom|chechek|cjk|diwani|ekran|elipbe|inchike|jelliy|kufi|mejnuntal|qara|qolyazma|teng|title|tor|tuz ?(neqish|tom))|mpush|n ?(dinaru|jamo|graphic|taza|vada|yetgul)|ni(kurd|space|versalis)|roob|rw ?classico)/i,
426 "v" => qr/^(veranda|vn ?urwclassico)/i,
427 "w" => qr/^(waree)/i,
428 "y" => qr/^(yanone)/i,
429 "z" => qr/^(zekton|zero)/i,
432 "value" => SCRIPT, # Script
433 "a" => qr/^a(becedario|ir ?cut|ugie|uriocus ?kalligraph)/i,
434 "b" => qr/^b(reip|rush ?script)/i,
435 "c" => qr/^(chancery)/i,
436 "d" => qr/^(dancing)/i,
437 "e" => qr/^(elegante)/i,
438 "f" => qr/^femkeklaver/i,
439 "j" => qr/^jsmath.?(rsfs)/i,
440 "k" => qr/^(kaushan|karumbi|kristi)/i,
441 "m" => qr/^(math ?jax.?script|miama)/i,
442 "n" => qr/^(nanum (brush|pen) script)/i,
444 "q" => qr/^qt( ?black ?forest|arabian|boulevard|brush ?stroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
445 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
446 "t" => qr/^typo ?script/i,
447 "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
451 "value" => FRAKTUR, # Fraktur
452 "b" => qr/^boondox ?fraktur/i,
454 "j" => qr/^(jsmath.?euf)/i,
455 "m" => qr/^(missaali)/i,
456 "o" => qr/^(oldania)/i,
457 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london) ?scroll)/i,
458 "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
462 "value" => FANCY, # Fancy
463 "a" => qr/^a(bandoned|bberancy|driator|irmole|lmendra ?display|lmonte (snow|woodgrain)|nalecta|ni|nklepants|nn ?stone|oyagi|rt ?nouveau ?caps|stron|xaxa)/i,
464 "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,
465 "c" => qr/^c(retino|msy|abin ?sketch|arbon|arolingan|harles|hicken|hilanka|hr\d)/i,
467 "e" => qr/^electorate/i,
468 "f" => qr/^frederika/i,
469 "g" => qr/^(gfs.?theo)/i,
470 "j" => qr/^jsmath.cmsy/i,
471 "k" => qr/^keter|kicking|kredit|kouzan/i,
473 "q" => qr/^qtcaslan ?open/i,
474 "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
475 "v" => qr/^vectroid/i,
479 "value" => INITIALS, # Initials
480 "c" => qr/^carrick/i,
481 "e" => qr/^(eb.?garamond.?init)/i,
482 "t" => qr/^typographer/i,
483 "y" => qr/^(yinit)/i,
487 "value" => SYMBOL, # Symbol
488 "a" => qr/^a(cademicons|lblant|lianna|mar|nka|rb?\d|rchaic|rrow|rs|rt[mt]|ssy(rb\d+)?\b|miri ?quran|mit\b)/i,
489 "b" => qr/^b(aby ?jeepers|bding|euron|guq|lex|lsy|oondox ?upr|ullets|urma)/i,
490 "c" => qr/^c(aladings|cicons|hess|msy|mex|apacitor|ounterscraps)/i,
491 "d" => qr/^(dingbats|drmsym|d05)/i,
492 "e" => qr/^e(lusiveicons|mmentaler|moji|sint|uterpe)/i,
493 "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
494 "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot).?classic|complutum))/i,
495 "h" => qr/^h(ots|ershey)/i,
496 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
497 "l" => qr/^l(cmsy|msam|ohit ?(Assamese|Bengali|Gujarati|Gurmukhi|Kannada|Malayalam|Marathi|Nepali|Odia|Tamil))/i,
498 "m" => qr/^(marvosym|material|msam|msbm)/i,
499 "n" => qr/^(noto.*(emoji|brahmi))/i,
500 "o" => qr/^(octicons)/i,
502 "q" => qr/^(qtding ?bits)/i,
503 "s" => qr/^s(emafor|kak|tmary|s?msam|tix ?math)/i,
504 "t" => qr/^(te ?xxslh?[du]|typicons|twemoji)/i,
505 "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
506 "w" => qr/^w(ebdings|asy|elfare ?brat)/i,
509 my %smallcapFonts = (
510 "value" => SMALLCAP | SERIF,
511 "c" => qr/^c(s[ct]sc\d|inzel|omputer ?modern ?sans ?italic ?regular ?\d)/i,
512 "d" => qr/^drm(it)?sc\d/i,
513 "f" => qr/^fetamont.?script/i,
514 "n" => qr/^newtxb?ttsc/i,
515 "s" => qr/^(screengem|sf.?kp.?sc)/i,
516 "t" => qr/^t1?xb?ttsc/i,
517 "v" => qr/^vn ?cccsc\d/i,
520 for my $cmd (@cmds) {
521 if (open(FI, "$cmd |")) {
522 NXTLINE: while (my $l = <FI>) {
524 while ($l !~ /abcd$/) {
530 if ($l =~ /file=\"([^\"]+)\"/) {
532 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
533 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
534 print "Unhandled extension for file $file\n";
538 if (! defined($fontpriority{$fonttype})) {
539 print "Added extension $fonttype for file $file\n";
540 $fontpriority{$fonttype} = $nexttype;
545 if ($l =~ / lang=\"([^\"]+)\"/) {
546 my @ll = split(/\|/, $1);
548 $usedlangs{&convertlang($lx)} = 1;
552 for my $lang (@langs) {
553 next NXTLINE if (! defined($usedlangs{$lang}));
555 my ($fullname, $fuidx) = &getVal($l, "fn", "fnl", -1);
556 my ($style, $fsidx) = &getVal($l, "style", "stylelang", $fuidx);
557 $style =~ s/^\\040//;
558 my ($family, $faidx) = &getVal($l, "family", "flang", $fsidx);
560 my $postscriptname = "";
561 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
562 $postscriptname = $1;
565 ($fontname, $style) = &buildFontName($family, $style);
566 if (defined($options{NFontName})) {
567 for my $fn (@{$options{NFontName}}) {
568 next NXTLINE if ($fontname =~ $fn);
571 if (defined($options{FontName})) {
572 for my $fn (@{$options{FontName}}) {
573 next NXTLINE if ($fontname !~ $fn);
578 if ($l =~ / charset=\"([^\"]+)\"/) {
579 my @list = split(/\s+/, $1);
581 my ($l, $h) = split('-', $e);
582 $h = $l if (! defined($h));
583 push(@charlist, [hex($l), hex($h)]);
586 if ($icontains & UCCONTAINS) {
587 for my $g (@{$options{Contains}}) {
588 next NXTLINE if (! contains($g, \@charlist));
591 if ($icontains & UCNCONTAINS) {
592 for my $g (@{$options{NContains}}) {
593 # Ignore if ANY char exist in @charlist
594 for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
595 next NXTLINE if (contains([$i,$i], \@charlist));
604 my $properties = getproperties($l, $fontname, $style, \@errors);
605 if ($iproperty & UPPROPERTY) {
606 for my $pn (@{$options{Property}}) {
607 next NXTLINE if ($properties !~ /$pn/i);
610 if ($iproperty & UPNPROPERTY) {
611 for my $pn (@{$options{NProperty}}) {
612 next NXTLINE if ($properties =~ /$pn/i);
615 if ($iproperty & UPPPROPERTIES) {
616 $props .= " ($properties)";
618 if ($iproperty & UPWPROPERTIES) {
619 $wprops .= " ($properties)";
622 if (exists($options{PrintLangs})) {
623 $props .= '(' . join(',', sort keys %usedlangs) . ')';
625 if (exists($options{PrintCharset})) {
626 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
631 if ($l =~ / script=\"([^\"]+)\"/) {
632 @scripts = split(/\s+/, $1);
633 for my $ent (@scripts) {
634 $ent =~ s/^\s*otlayout://;
637 $scripts = join(',', @scripts);
639 if ($iscript & USMSCRIPT) {
640 next NXTLINE if (! &ismathfont($fontname,\@scripts));
642 if ($iscript & USPSCRIPT) {
643 $props .= "($scripts)";
645 if (!defined($scripts[0])) {
646 # No script defined in font, so check only $options{Scripts}
647 next NXTLINE if ($iscript & USSCRIPT);
650 if ($iscript & USSCRIPT) {
651 for my $s (@{$options{Scripts}}) {
652 next NXTLINE if ($scripts !~ /$s/i);
655 if ($iscript & USNSCRIPT) {
656 for my $s (@{$options{NScripts}}) {
657 next NXTLINE if ($scripts =~ /$s/i);
663 if ($l =~ /foundry=\"([^\"]+)\"/) {
665 $foundry =~ s/^\s+//;
666 $foundry =~ s/\s+$//;
668 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
669 # Apparently not the first one, so add some info
670 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
671 if (defined($errors[0])) {
672 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
674 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
675 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info of file: " . $collectedfonts{$fontname}->{$foundry}->{file});
678 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info from file: $file");
683 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
685 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
686 $collectedfonts{$fontname}->{$foundry}->{wprops} = $wprops;
687 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
688 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
694 for my $fontname (sort keys %collectedfonts) {
695 my @foundries = sort keys %{$collectedfonts{$fontname}};
696 my $printfoundries = 1;
697 if (defined($foundries[1])) {
700 for my $foundry (@foundries) {
701 if (exists($options{PrintWarnings})) {
702 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
706 my $fn = "Font : $fontname";
707 if ($printfoundries && ($foundry ne "")) {
708 $fn .= " \[$foundry\]";
711 print INFOS $fn if (defined($options{Write}));
712 print $collectedfonts{$fontname}->{$foundry}->{props};
713 print INFOS $collectedfonts{$fontname}->{$foundry}->{wprops} if (defined($options{Write}));
714 print INFOS ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n" if (defined($options{Write}));
715 if (exists($options{PrintFiles})) {
716 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
723 close(INFOS) if (defined($options{Write}));
726 #################################################################################
730 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
731 my ($x, $y) = ($1, $3);
733 $ilang = lc($x) . '-' . lc($y);
744 my ($l, $islang, $txt, $rres) = @_;
746 if ($l =~ /$txt=\"([^\"]+)\"/) {
747 @res = split(',', $1);
750 $lg = &convertlang($lg);
759 my ($lang, $rlangs) = @_;
762 for (my $i = 0; defined($rlangs->[$i]); $i++) {
763 if ($rlangs->[$i] eq $lang) {
772 my ($l, $txtval, $txtlang, $startentry) = @_;
775 &extractlist($l, 0, $txtval, \@values);
776 return("", -1) if (! defined($values[0]));
777 &extractlist($l, 1, $txtlang, \@langs);
778 my $i = &getIndexes("en", \@langs);
780 my $actualentry = -1;
783 if (defined($values[$k])) {
785 if ($startentry < 0) {
786 if (length($values[$k]) > length($res)) {
788 $usedentry = $actualentry;
791 elsif ($actualentry == $startentry) {
793 $usedentry = $actualentry;
797 # select the longest entry if possible
798 if (length($values[$k]) > length($res)) {
800 $usedentry = $actualentry;
805 return($values[0], -1) if ($res eq "");
806 return($res, $usedentry);
809 sub getsinglevalue($$$)
811 my ($l, $txt, $rMap, $rget) = @_;
813 if ($l =~ / $txt=(\d+)/) {
815 # Search for nearest value to $val
816 if (defined($rMap->{$val})) {
817 return($rMap->{$val});
821 for my $key (keys %{$rMap}) {
822 next if ($key !~ /^\d+$/);
823 my $diff = abs($key - $val);
828 elsif ($diff == $minv) {
834 if (! defined($rMap->{$maxv})) {
835 print "ERROR2: txt=$txt, val=$val\n";
839 return($rMap->{$maxv} . "+$minv");
842 return($rMap->{$maxv} . "-$minv");
852 my ($txt, $val) = @_;
853 return("$txt($val)");
858 my ($fontname, $style) = @_;
860 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
863 elsif ($fontname =~ /gothic|dotum|gulim/i) {
864 if ($fontname =~ /bisrat gothic/i) {
867 elsif ($fontname !~ /hershey/i) {
871 elsif ($fontname =~ /^(js ?math.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
872 $resftype |= DOUBLESTROKE; # Double stroke (math font)
874 if ($fontname =~ /serif|times|mincho|batang/i) {
875 $resftype |= SERIF; # Serif
877 if ($fontname =~ /initial(s|en)/i) {
878 $resftype |= INITIALS;
879 if ($fontname =~ /^linux ?libertine/i) {
883 if ($fontname =~ /participants/i) {
884 $resftype |= SANS|FANCY;
886 if ($fontname =~ /symbol|cherokee/i) {
887 if ($fontname !~ /^(symbola|asap)/i) {
889 if ($fontname =~ /^(ams ?math|computer modern bright msb)/i) {
890 $resftype |= DOUBLESTROKE | SERIF;
894 if ($fontname =~ /callig/i) {
897 if ($fontname =~ /\bS(mall)?C(aps)\b/i) {
898 if ($fontname !~ /^noto/i) {
899 $resftype |= SMALLCAP|SERIF;
902 # Now check for fonts without a hint in font name
903 if ($fontname =~ /^([a-z])/i) {
905 # check the mutual exclusive first
906 for my $rFonts (\%fraktFonts, \%scriptFonts, \%sansFonts, \%serifFonts) {
907 if (defined($rFonts->{$key})) {
908 if ($fontname =~ $rFonts->{$key}) {
909 $resftype |= $rFonts->{"value"};
914 for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts, \%smallcapFonts) {
915 if (defined($rFonts->{$key})) {
916 if ($fontname =~ $rFonts->{$key}) {
917 $resftype |= $rFonts->{"value"};
922 if ("$fontname" =~ /^bpg/i) {
923 if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
924 $resftype |= SERIF; # Serif
927 $resftype |= SANS; # Sans Serif
930 elsif ("$fontname" =~ /^dustismo/i) {
931 if ("$fontname" =~ /^dustismo roman/i) {
932 $resftype |= SERIF; # Serif
935 $resftype |= SANS; # Sans Serif
938 elsif ("$fontname" =~ /^go\b/i) {
939 if ("$fontname" =~ /^go mono/i) {
940 $resftype |= SERIF; # Serif
943 $resftype |= SANS; # Sans Serif
948 if ($resftype == 0) {
949 $resftype = $ftypes{default};
952 # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
953 if ($resftype & FRAKTUR) {
954 $resftype &= ~(SANS|SERIF|SCRIPT);
956 elsif ($resftype & SCRIPT) {
957 $resftype &= ~(SANS|SERIF);
959 elsif ($resftype & SANS) {
963 for (my $i = 1; $i < 513; $i *= 2) {
964 if ($resftype & $i) {
965 push(@ft, $ftypes{$i});
968 return(join(',', @ft));
973 my ($fontname, $style) = @_;
975 for my $info ($style, $fontname) {
976 for my $key (keys %weights) {
977 next if ($key !~ /^\d+$/);
978 my $val = $weights{$key};
979 if ($info =~ /\b$val\b/i) {
989 my ($fontname, $style) = @_;
991 for my $key (keys %widths) {
992 next if ($key !~ /^\d+$/);
993 for my $info ($style, $fontname) {
994 if ($info =~ /\b$widths{$key}\b/i) {
995 return($widths{$key});
997 if ($info =~ /\bRegular\b/) {
998 if (!defined($result)) {
999 $result = $widths{100};
1009 my ($fontname, $style) = @_;
1010 for my $key (keys %slants) {
1011 next if ($key !~ /^\d+$/);
1012 if ($style =~ /\b$slants{$key}\b/i) {
1013 return($slants{$key});
1021 my ($fontname, $style) = @_;
1022 for my $key (keys %spacings) {
1023 next if ($key !~ /^\d+$/);
1024 if ($style =~ /\b$spacings{$key}\b/i) {
1025 return($spacings{$key});
1028 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
1029 return($spacings{100}); # Mono
1038 my ($fontname, $rCapability) = @_;
1040 return 1 if ($fontname =~ /math/i);
1041 for my $cap (@{$rCapability}) {
1042 return 1 if ($cap eq "math");
1047 sub getproperties($$$$)
1049 my ($l, $fontname, $style, $rerrors) = @_;
1050 my $newstyle = &correctstyle($style);
1051 my $newfam = &correctstyle($fontname);
1052 my @properties = ();
1054 for my $txt (qw(ftype weight width slant spacing)) {
1056 eval("\$map = " . '\%' . $txt . 's');
1057 eval('$rget = \&' . "get$txt");
1058 my $val2 = getsinglevalue($l, $txt, $map);
1059 my $val1 = $rget->($newfam, $newstyle);
1061 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
1062 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/i)){
1063 # style overrides weight and slant
1064 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
1067 elsif ($newfam =~ /$val1/) {
1068 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
1072 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
1076 elsif (! defined($val2)) {
1082 if (defined($val)) {
1083 push(@properties, &addTxt($txt,$val));
1086 if (defined($map->{"default"})) {
1087 push(@properties, &addTxt($txt,$map->{"default"}));
1090 push(@{$rerrors}, "Undefined value for $txt");
1094 return(join(' ', @properties));
1100 $style =~ s/^\s*\d+\s*//;
1101 $style =~ s/\s*\d+$//;
1102 $style =~ s/italic/ Italic/i;
1103 $style =~ s/oblique/ Oblique/i;
1104 $style =~ s/[\-_]/ /g;
1105 $style =~ s/\breg\b/Regular/i;
1106 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
1107 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
1108 $style =~ s/medium/Medium /i;
1109 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
1110 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
1111 $style =~ s/\bmed\b/Medium /i;
1112 $style =~ s/\bex(pd|t)\b/Expanded/i;
1113 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
1114 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
1115 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
1116 $style =~ s/[sd]emi ?light/SemiLight/i;
1117 $style =~ s/\b[sd]emi\b/SemiBold/i;
1118 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
1119 $style =~ s/light/Light /i;
1120 $style =~ s/\blt\b/Light /i;
1121 $style =~ s/(ultra|extra) ?(light|lt)/ExtraLight /i;
1122 $style =~ s/\bheavy\b/Extrabold/i;
1123 $style =~ s/\bhairline\b/Extralight/i;
1124 $style =~ s/\bcond\b/Condensed/i;
1125 $style =~ s/(roman)?slanted/ Italic/i;
1126 $style =~ s/\bslant\b/Italic/i;
1127 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
1128 $style =~ s/w3 mono/Dual/i;
1129 $style =~ s/Regul[ea]r/Regular/i;
1130 $style =~ s/Megablack/ExtraBlack/i;
1136 # return list of unicode values of the input string
1137 #Allow input of intervals (e.g. 'a-z')
1138 sub decimalUnicode($)
1142 # Convert to unicode chars first
1143 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
1144 my ($prev, $d, $post) = ($1, $2, $3);
1145 if ($d =~ /^0?x(.+)$/) {
1148 my $chr = encode('utf-8', chr($d));
1149 $a = $prev . $chr . $post;
1151 # $a is now a string of unicode chars
1152 my $u = decode('utf-8', $a);
1153 my @a = split(//, $u);
1157 if ($x eq '-') { # Interval
1161 if ($interval && defined($start)) {
1162 if (ord($x) < $start) {
1163 for (my $i = $start - 1; $i >= ord($x); $i--) {
1168 for (my $i = $start + 1; $i <= ord($x); $i++) {
1184 # check if the glyph-values in interval @{$ri} are contained
1185 # in one of the (sorted) intervals
1189 # ...re0..........re1...
1190 # ......start..end......
1191 my ($ri, $rList) = @_;
1192 my $start = $ri->[0];
1195 for my $re (@{$rList}) {
1196 next if ($re->[1] < $start);
1197 # now we found a possible matching interval
1198 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1204 sub sprintIntervalls($)
1208 for my $rE (@{$rList}) {
1209 if ($rE->[0] != $rE->[1]) {
1210 push(@out, $rE->[0] . '-' . $rE->[1]);
1213 push(@out, $rE->[0]);
1216 return join(',', @out);
1219 sub buildFontName($$)
1221 my ($family, $style) = @_;
1224 $style =~ s/\\040//;
1225 $family =~ s/\\040/\-/;
1226 $family =~ s/\bcond\b/Condensed/i;
1227 $family =~ s/\bblk\b/Black/i;
1228 $family =~ s/\bsembd\b/SemiBold/i;
1229 $family =~ s/\bsemcond\b/SemiCondensed/i;
1230 $family =~ s/\bextcond\b/ExtraCondensed/i;
1231 $family =~ s/\bextbd\b/ExtraBold/i;
1232 $family =~ s/\bextlt\b/ExtraLight/i;
1233 $family =~ s/\bmed\b/Medium/i;
1235 # Split the family name at the border lowercase <-> uppercase characters
1236 # except if family starts with "TeX" or "DejaVu", etc
1237 if ($family =~ s/^((La|cw|PL)?TeX|LyX|DejaVu|MarVoSym|PL)//) {
1239 if ($family =~ /^[A-Z]/) {
1244 if ($family =~ /^([A-Z]*[a-z]+)([A-Z]\w+)\b(.*)$/) {
1245 $family = $1 . splitatlU($2) . $3;
1247 $family =~ s/^Ant Polt\b/Antykwa Poltawskiego/;
1248 $family =~ s/\b(Semi|Extra) (Bold|Condensed|Expanded|Light)\b/$1$2/;
1249 $family = $prefix . $family;
1251 if ($style =~ s/^((La|cw|PL)?TeX|LyX|DejaVu|MarVoSym|PL)//) {
1255 push(@style, &splitStyle($style));
1256 for my $st (@style) {
1258 if ($family !~ s/$st/$st/i) {
1262 # check if $st in $family starts with ' '
1263 $family =~ s/(\w)$st/$1 $st/i;
1267 return($result, join(' ', @style));
1270 # split text at change from lower case to upper case
1274 if ($txt =~ /^([A-Z]+[a-z]*)(.*)$/) {
1275 if (defined($mapShortcuts{$1})) {
1276 return(" " . $mapShortcuts{$1} . splitatlU($2));
1279 return(" $1" . splitatlU($2));
1287 my @in = split(/[- ]/, $_[0]);
1291 while ($en =~ s/^([A-Z][a-z]+)//) {
1293 if ($found =~ /^(Semi|Extra)$/) {
1297 elsif (defined($mapShortcuts{$found})) {
1298 $found = $mapShortcuts{$found};
1300 push(@result, "$prefix$found");
1304 push(@result, "$prefix$en");