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 # for UseProperty (UP)
50 UPPROPERTY => 1, # select
51 UPNPROPERTY => 2, # deselect
52 UPPPROPERTIES => 4, # print
53 UPWPROPERTIES => 8, # write to a file
55 # for UseCharsets (UC)
56 UCCONTAINS => 1, # select
57 UCNCONTAINS => 2, # deselect
58 UCPCONTAINS => 4, # print
61 USSCRIPT => 1, # select
62 USNSCRIPT => 2, # deselect
63 USMSCRIPT => 4, # math
64 USPSCRIPT => 8, # print
65 USWSCRIPT => 16, # write to a file
68 # These will be set according to options
69 my $iproperty = 0; # info for Use Properties
70 my $icontains = 0; # info for Use Charsets
71 my $iscript = 0; # info for Use Scripts
74 sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
76 sub getVal($$$$); # my ($l, $txtval, $txtlang, $combine) = @_;
77 sub getproperties($$$$);
80 sub decimalUnicode($);
82 sub sprintIntervalls($);
83 sub buildFontName($$);
84 sub splitatlU($); # split text at change from lower case to upper case
87 # Following fields for a parameter can be defined:
88 # fieldname: Name of entry in %options
89 # type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
90 # alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
91 # listsep: Separator for multiple data
92 # comment: Parameter description
94 # help + verbose already handled in 'GetOptions'
96 {fieldname => "FontName", listsep => ',',
97 type => "=s", alias => ["name"],
98 comment => "Select font-names matching these (comma separated) regexes"},],
100 {fieldname => "NFontName",
101 type => "=s", listsep => ',',
102 comment => "Select font-names NOT matching these (comma separated) regexes"},],
104 {fieldname => "Property",
105 type => "=s", listsep => ',',
106 comment => "Select fonts with properties matching these (comma separated) regexes"},],
108 {fieldname => "NProperty",
109 type => "=s", listsep => ',',
110 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
112 {fieldname => "Scripts",
113 type => "=s", listsep => ',',
114 comment => "Select fonts with scripts matching these (comma separated) regexes"},],
116 {fieldname => "NScripts",
117 type => "=s", listsep => ',',
118 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
120 {fieldname => "Math",
121 comment => "Select fonts probably containing math glyphs"},],
123 {fieldname => "Contains", alias => ["contains"],
124 type => "=s", listsep => ',',
125 comment => "Select fonts containing all these (possibly comma separated) glyphs",
126 comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
128 {fieldname => "NContains",
129 type => "=s", listsep => ',',
130 comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
131 comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
133 {fieldname => "Lang",
134 type => "=s", alias=>["lang"],
135 comment => "Comma separated list of desired languages"},],
137 {fieldname => "PrintCharset", alias => ["printcharset"],
138 comment => "Print intervals of supported unicode character values"},],
140 {fieldname => "PrintLangs", alias => ["printlangs"],
141 comment => "Print supported languages"},],
143 {fieldname => "PrintProperties", alias => ["printproperties"],
144 comment => "Print properties from weight, slant and width"},],
146 {fieldname => "PrintScripts", alias => ["printscripts"],
147 comment => "Print supported scripts"},],
149 {fieldname => "PrintFiles", alias => ["printfiles"],
150 comment => "Print font file names"},],
152 {fieldname => "PrintWarnings",
153 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
155 {fieldname => "Write",
156 type => "=s", alias => ["writefile"],
157 comment => "Write to a file for later use"},],
159 my %options = %{&handleOptions(\@optionsDef)};
161 $options{Lang} = "" if (! defined($options{Lang}));
163 #############################################################
165 "Cond" => "Condensed",
166 "Expd" => "Expanded",
173 my @langs = split(',', $options{Lang});
174 for my $lg (@langs) {
175 $lg = &convertlang($lg);
178 $iproperty |= UPPROPERTY if (defined($options{Property}));
179 $iproperty |= UPNPROPERTY if (defined($options{NProperty}));
180 $iproperty |= UPPPROPERTIES if (exists($options{PrintProperties}));
182 $icontains |= UCCONTAINS if (defined($options{Contains}));
183 $icontains |= UCNCONTAINS if (defined($options{NContains}));
184 $icontains |= UCPCONTAINS if (exists($options{PrintCharset}));
186 $iscript |= USSCRIPT if (defined($options{Scripts}));
187 $iscript |= USNSCRIPT if (defined($options{NScripts}));
188 $iscript |= USMSCRIPT if (exists($options{Math}));
189 $iscript |= USPSCRIPT if (exists($options{PrintScripts}));
191 if (defined($options{Write})) {
192 if (! open(INFOS, '>', $options{Write})) {
193 die("Could not open file $options{Write} for write");
195 $iproperty |= UPWPROPERTIES;
197 # $iscript |= USWSCRIPT;
200 for my $charFld ("Contains", "NContains") {
201 if (defined($options{$charFld})) {
202 my %glyphs = (); # To ignore duplicates
203 for my $a1 (@{$options{$charFld}}) {
204 for my $e (decimalUnicode($a1)) {
209 my @glyphs = sort {$a <=> $b;} keys %glyphs;
211 # $options{$charFld} no longer needed, so use it for unicode-point intervalls
212 $options{$charFld} = [];
213 my ($first, $last) = (undef, undef);
214 for my $i (@glyphs) {
215 if (! defined($last)) {
224 push(@{$options{$charFld}}, [$first, $last]);
228 if (defined($last)) {
229 push(@{$options{$charFld}}, [$first, $last]);
231 if (exists($options{verbose})) {
232 if ($charFld eq "Contains") {
233 print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
236 print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
242 for my $fn ("FontName", "NFontName") {
243 if (defined($options{$fn})) {
244 # split each entry and make a compiled regex
245 # Allow space between all characters
246 for my $e (@{$options{$fn}}) {
247 if ($e =~ /(\^|\\|\||\[|\]|\(|\)|\*|\+|\?)/) {
248 # already regex, don't manipulate
252 my $u = decode('utf-8', $e);
253 my $fill = decode('utf-8', "\\s?");
254 my @u = split(//, $u);
255 my $ud = join($fill, @u);
256 my $e1 = encode('utf-8', $ud);
264 if (defined($langs[0])) {
265 $cmd .= " :lang=" . join(',', @langs);
268 my $format = "foundry=\"%{foundry}\"" .
269 " postscriptname=\"%{postscriptname}\"" .
270 " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
271 " family=\"%{family}\" flang=\"%{familylang}\" " .
272 " style=\"%{style}\" stylelang=\"%{stylelang}\"";
275 $format .= " script=\"%{capability}\"";
277 if (exists($options{PrintLangs}) || defined($langs[0])) {
278 $format .= " lang=\"%{lang}\"";
281 $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
284 $format .= " charset=\"%{charset}\"";
286 $format .= " file=\"%{file}\" abcd\\n";
287 $cmd .= " -f '$format'";
293 # using '()' to prevent the initializer to take
294 # the key as a string. (Constants in perl _are_ functions without argument)
297 SCRIPT() => "Script",
298 FRAKTUR() => "Fraktur",
299 DOUBLESTROKE() => "DoubleStroke",
301 INITIALS() => "Initials",
302 SYMBOL() => "Symbol",
303 SMALLCAP() => "SmallCap",
329 50 => "Ultracondensed",
330 63 => "Extracondensed",
332 87 => "Semicondensed",
334 113 => "Semiexpanded",
336 150 => "Extraexpanded",
337 200 => "Ultraexpanded",
345 "default" => "Proportional",
348 # Build reverse mappings, (not needed yet)
349 for my $txt (qw(ftypes weights slants widths spacings)) {
351 eval "\$map = \\%$txt";
352 for my $key (keys %{$map}) {
353 next if ($key !~ /^\d+$/);
354 my $value = lc($map->{$key});
355 $map->{"r"}->{$value} = $key;
362 my %collectedfonts = ();
364 otf => 0, # type 2, opentype CFF (Compact Font Format)
365 ttc => 1.1, # type 1 (True Type font Collection)
366 ttf => 1.2, # type 1 (True Type Font)
367 woff=> 1.3, # type 1 (Web Open Font Format)
368 t1 => 1.4, # type 1 (postscript)
369 pfb => 1.5, # type 1 (Printer Font Binary)
370 pfa => 1.6, # type 1 (Printer Font Ascii)
371 pfm => 2, # requires associated .pfb file
372 pcf => 5, # Bitmap (Packaged Collaboration Files)?
377 # some extra serif fonts
379 "g" => qr/^gfs ?(didot)/i,
381 # list of regexes for known sans serif fonts
383 "value" => SANS, # Sans serif
384 "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,
385 "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,
386 "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,
387 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
388 "e" => qr/^(electron|engebrechtre)/i,
389 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
390 "g" => qr/^g(ardiner|aruda|fs ?neo|illius|ood ?times|ranada|raph|uanine|unplay)/i,
391 "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
392 "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
393 "j" => qr/^j(ara|ura|s ?math.?bbold)/i,
394 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kp ?mono|kurier|kustom)/i,
395 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation ?mono|ibre franklin|ibris|inux biolinum|obster|ogix|ohit ?(devana|telugu)|oma)/i,
396 "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,
397 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice|noto ?mono)/i,
398 "o" => qr/^(ocr|okolaks|open ?dyslexic|ostorah|ouhud|over|oxygen)/i,
399 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
400 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
401 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
402 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
403 "t" => qr/^(tarablus|teen|tex ?gyre ?(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
404 "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,
405 "v" => qr/^(veranda|vn ?urwclassico)/i,
406 "w" => qr/^(waree)/i,
407 "y" => qr/^(yanone)/i,
408 "z" => qr/^(zekton|zero)/i,
411 "value" => SCRIPT, # Script
412 "a" => qr/^a(becedario|ir ?cut|ugie|uriocus ?kalligraph)/i,
413 "b" => qr/^b(reip|rush ?script)/i,
414 "c" => qr/^(chancery)/i,
415 "d" => qr/^(dancing)/i,
416 "e" => qr/^(elegante)/i,
417 "f" => qr/^femkeklaver/i,
418 "j" => qr/^jsmath.?(rsfs)/i,
419 "k" => qr/^(kaushan|karumbi|kristi)/i,
420 "m" => qr/^(math ?jax.?script|miama)/i,
421 "n" => qr/^(nanum (brush|pen) script)/i,
423 "q" => qr/^qt( ?black ?forest|arabian|boulevard|brush ?stroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
424 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
425 "t" => qr/^typo ?script/i,
426 "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
430 "value" => FRAKTUR, # Fraktur
431 "b" => qr/^boondox ?fraktur/i,
433 "j" => qr/^(jsmath.?euf)/i,
434 "m" => qr/^(missaali)/i,
435 "o" => qr/^(oldania)/i,
436 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london) ?scroll)/i,
437 "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
441 "value" => FANCY, # Fancy
442 "a" => qr/^a(bandoned|bberancy|driator|irmole|lmendra ?display|lmonte (snow|woodgrain)|nalecta|ni|nklepants|nn ?stone|oyagi|rt ?nouveau ?caps|stron|xaxa)/i,
443 "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,
444 "c" => qr/^c(retino|msy|abin ?sketch|arbon|arolingan|harles|hicken|hilanka|hr\d)/i,
446 "e" => qr/^electorate/i,
447 "f" => qr/^frederika/i,
448 "g" => qr/^(gfs.?theo)/i,
449 "j" => qr/^jsmath.cmsy/i,
450 "k" => qr/^keter|kicking|kredit|kouzan/i,
452 "q" => qr/^qtcaslan ?open/i,
453 "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
454 "v" => qr/^vectroid/i,
458 "value" => INITIALS, # Initials
459 "c" => qr/^carrick/i,
460 "e" => qr/^(eb.?garamond.?init)/i,
461 "t" => qr/^typographer/i,
462 "y" => qr/^(yinit)/i,
466 "value" => SYMBOL, # Symbol
467 "a" => qr/^a(cademicons|lblant|lianna|mar|nka|rb?\d|rchaic|rrow|rs|rt[mt]|ssy(rb\d+)?\b|miri ?quran|mit\b)/i,
468 "b" => qr/^b(aby ?jeepers|bding|euron|guq|lex|lsy|oondox ?upr|ullets|urma)/i,
469 "c" => qr/^c(aladings|cicons|hess|msy|mex|apacitor|ounterscraps)/i,
470 "d" => qr/^(dingbats|drmsym|d05)/i,
471 "e" => qr/^e(lusiveicons|mmentaler|moji|sint|uterpe)/i,
472 "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
473 "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot).?classic|complutum))/i,
474 "h" => qr/^h(ots|ershey)/i,
475 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
476 "l" => qr/^l(cmsy|msam|ohit ?(Assamese|Bengali|Gujarati|Gurmukhi|Kannada|Malayalam|Marathi|Nepali|Odia|Tamil))/i,
477 "m" => qr/^(marvosym|material|msam|msbm)/i,
478 "n" => qr/^(noto.*(emoji|brahmi))/i,
479 "o" => qr/^(octicons)/i,
481 "q" => qr/^(qtding ?bits)/i,
482 "s" => qr/^s(emafor|kak|tmary|s?msam|tix ?math)/i,
483 "t" => qr/^(te ?xxslh?[du]|typicons|twemoji)/i,
484 "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
485 "w" => qr/^w(ebdings|asy|elfare ?brat)/i,
488 my %smallcapFonts = (
489 "value" => SMALLCAP | SERIF,
490 "c" => qr/^c(s[ct]sc\d|inzel|omputer ?modern ?sans ?italic ?regular ?\d)/i,
491 "d" => qr/^drm(it)?sc\d/i,
492 "f" => qr/^fetamont.?script/i,
493 "n" => qr/^newtxb?ttsc/i,
494 "s" => qr/^(screengem|sf.?kp.?sc)/i,
495 "t" => qr/^t1?xb?ttsc/i,
496 "v" => qr/^vn ?cccsc\d/i,
499 if (open(FI, "$cmd |")) {
500 NXTLINE: while (my $l = <FI>) {
502 while ($l !~ /abcd$/) {
508 if ($l =~ /file=\"([^\"]+)\"/) {
510 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
511 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
512 print "Unhandled extension for file $file\n";
516 if (! defined($fontpriority{$fonttype})) {
517 print "Added extension $fonttype for file $file\n";
518 $fontpriority{$fonttype} = $nexttype;
523 if ($l =~ / lang=\"([^\"]+)\"/) {
524 my @ll = split(/\|/, $1);
526 $usedlangs{&convertlang($lx)} = 1;
530 for my $lang (@langs) {
531 next NXTLINE if (! defined($usedlangs{$lang}));
533 my ($fullname, $fuidx) = &getVal($l, "fn", "fnl", -1);
534 my ($style, $fsidx) = &getVal($l, "style", "stylelang", $fuidx);
535 $style =~ s/^\\040//;
536 my ($family, $faidx) = &getVal($l, "family", "flang", $fsidx);
538 my $postscriptname = "";
539 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
540 $postscriptname = $1;
543 ($fontname, $style) = &buildFontName($family, $style);
544 if (defined($options{NFontName})) {
545 for my $fn (@{$options{NFontName}}) {
546 next NXTLINE if ($fontname =~ $fn);
549 if (defined($options{FontName})) {
550 for my $fn (@{$options{FontName}}) {
551 next NXTLINE if ($fontname !~ $fn);
556 if ($l =~ / charset=\"([^\"]+)\"/) {
557 my @list = split(/\s+/, $1);
559 my ($l, $h) = split('-', $e);
560 $h = $l if (! defined($h));
561 push(@charlist, [hex($l), hex($h)]);
564 if ($icontains & UCCONTAINS) {
565 for my $g (@{$options{Contains}}) {
566 next NXTLINE if (! contains($g, \@charlist));
569 if ($icontains & UCNCONTAINS) {
570 for my $g (@{$options{NContains}}) {
571 # Ignore if ANY char exist in @charlist
572 for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
573 next NXTLINE if (contains([$i,$i], \@charlist));
582 my $properties = getproperties($l, $fontname, $style, \@errors);
583 if ($iproperty & UPPROPERTY) {
584 for my $pn (@{$options{Property}}) {
585 next NXTLINE if ($properties !~ /$pn/i);
588 if ($iproperty & UPNPROPERTY) {
589 for my $pn (@{$options{NProperty}}) {
590 next NXTLINE if ($properties =~ /$pn/i);
593 if ($iproperty & UPPPROPERTIES) {
594 $props .= " ($properties)";
596 if ($iproperty & UPWPROPERTIES) {
597 $wprops .= " ($properties)";
600 if (exists($options{PrintLangs})) {
601 $props .= '(' . join(',', sort keys %usedlangs) . ')';
603 if (exists($options{PrintCharset})) {
604 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
609 if ($l =~ / script=\"([^\"]+)\"/) {
610 @scripts = split(/\s+/, $1);
611 for my $ent (@scripts) {
612 $ent =~ s/^\s*otlayout://;
615 $scripts = join(',', @scripts);
617 if ($iscript & USMSCRIPT) {
618 next NXTLINE if (! &ismathfont($fontname,\@scripts));
620 if ($iscript & USPSCRIPT) {
621 $props .= "($scripts)";
623 if (!defined($scripts[0])) {
624 # No script defined in font, so check only $options{Scripts}
625 next NXTLINE if ($iscript & USSCRIPT);
628 if ($iscript & USSCRIPT) {
629 for my $s (@{$options{Scripts}}) {
630 next NXTLINE if ($scripts !~ /$s/i);
633 if ($iscript & USNSCRIPT) {
634 for my $s (@{$options{NScripts}}) {
635 next NXTLINE if ($scripts =~ /$s/i);
641 if ($l =~ /foundry=\"([^\"]+)\"/) {
643 $foundry =~ s/^\s+//;
644 $foundry =~ s/\s+$//;
646 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
647 # Apparently not the first one, so add some info
648 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
649 if (defined($errors[0])) {
650 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
652 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
653 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info of file: " . $collectedfonts{$fontname}->{$foundry}->{file});
656 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info from file: $file");
661 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
663 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
664 $collectedfonts{$fontname}->{$foundry}->{wprops} = $wprops;
665 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
666 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
671 for my $fontname (sort keys %collectedfonts) {
672 my @foundries = sort keys %{$collectedfonts{$fontname}};
673 my $printfoundries = 1;
674 if (defined($foundries[1])) {
677 for my $foundry (@foundries) {
678 if (exists($options{PrintWarnings})) {
679 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
683 my $fn = "Font : $fontname";
684 if ($printfoundries && ($foundry ne "")) {
685 $fn .= " \[$foundry\]";
688 print INFOS $fn if (defined($options{Write}));
689 print $collectedfonts{$fontname}->{$foundry}->{props};
690 print INFOS $collectedfonts{$fontname}->{$foundry}->{wprops} if (defined($options{Write}));
691 print INFOS ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n" if (defined($options{Write}));
692 if (exists($options{PrintFiles})) {
693 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
700 close(INFOS) if (defined($options{Write}));
703 #################################################################################
707 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
708 my ($x, $y) = ($1, $3);
710 $ilang = lc($x) . '-' . lc($y);
721 my ($l, $islang, $txt, $rres) = @_;
723 if ($l =~ /$txt=\"([^\"]+)\"/) {
724 @res = split(',', $1);
727 $lg = &convertlang($lg);
736 my ($lang, $rlangs) = @_;
739 for (my $i = 0; defined($rlangs->[$i]); $i++) {
740 if ($rlangs->[$i] eq $lang) {
749 my ($l, $txtval, $txtlang, $startentry) = @_;
752 &extractlist($l, 0, $txtval, \@values);
753 return("", -1) if (! defined($values[0]));
754 &extractlist($l, 1, $txtlang, \@langs);
755 my $i = &getIndexes("en", \@langs);
757 my $actualentry = -1;
760 if (defined($values[$k])) {
762 if ($startentry < 0) {
763 if (length($values[$k]) > length($res)) {
765 $usedentry = $actualentry;
768 elsif ($actualentry == $startentry) {
770 $usedentry = $actualentry;
774 # select the longest entry if possible
775 if (length($values[$k]) > length($res)) {
777 $usedentry = $actualentry;
782 return($values[0], -1) if ($res eq "");
783 return($res, $usedentry);
786 sub getsinglevalue($$$)
788 my ($l, $txt, $rMap, $rget) = @_;
790 if ($l =~ / $txt=(\d+)/) {
792 # Search for nearest value to $val
793 if (defined($rMap->{$val})) {
794 return($rMap->{$val});
798 for my $key (keys %{$rMap}) {
799 next if ($key !~ /^\d+$/);
800 my $diff = abs($key - $val);
805 elsif ($diff == $minv) {
811 if (! defined($rMap->{$maxv})) {
812 print "ERROR2: txt=$txt, val=$val\n";
816 return($rMap->{$maxv} . "+$minv");
819 return($rMap->{$maxv} . "-$minv");
829 my ($txt, $val) = @_;
830 return("$txt($val)");
835 my ($fontname, $style) = @_;
837 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
840 elsif ($fontname =~ /gothic|dotum|gulim/i) {
841 if ($fontname =~ /bisrat gothic/i) {
844 elsif ($fontname !~ /hershey/i) {
848 elsif ($fontname =~ /^(js ?math.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
849 $resftype |= DOUBLESTROKE; # Double stroke (math font)
851 if ($fontname =~ /serif|times|mincho|batang/i) {
852 $resftype |= SERIF; # Serif
854 if ($fontname =~ /initial(s|en)/i) {
855 $resftype |= INITIALS;
856 if ($fontname =~ /^linux ?libertine/i) {
860 if ($fontname =~ /participants/i) {
861 $resftype |= SANS|FANCY;
863 if ($fontname =~ /symbol|cherokee/i) {
864 if ($fontname !~ /^(symbola|asap)/i) {
866 if ($fontname =~ /^(ams ?math|computer modern bright msb)/i) {
867 $resftype |= DOUBLESTROKE | SERIF;
871 if ($fontname =~ /callig/i) {
874 if ($fontname =~ /\bS(mall)?C(aps)\b/i) {
875 if ($fontname !~ /^noto/i) {
876 $resftype |= SMALLCAP|SERIF;
879 # Now check for fonts without a hint in font name
880 if ($fontname =~ /^([a-z])/i) {
882 # check the mutual exclusive first
883 for my $rFonts (\%fraktFonts, \%scriptFonts, \%sansFonts, \%serifFonts) {
884 if (defined($rFonts->{$key})) {
885 if ($fontname =~ $rFonts->{$key}) {
886 $resftype |= $rFonts->{"value"};
891 for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts, \%smallcapFonts) {
892 if (defined($rFonts->{$key})) {
893 if ($fontname =~ $rFonts->{$key}) {
894 $resftype |= $rFonts->{"value"};
899 if ("$fontname" =~ /^bpg/i) {
900 if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
901 $resftype |= SERIF; # Serif
904 $resftype |= SANS; # Sans Serif
907 elsif ("$fontname" =~ /^dustismo/i) {
908 if ("$fontname" =~ /^dustismo roman/i) {
909 $resftype |= SERIF; # Serif
912 $resftype |= SANS; # Sans Serif
915 elsif ("$fontname" =~ /^go\b/i) {
916 if ("$fontname" =~ /^go mono/i) {
917 $resftype |= SERIF; # Serif
920 $resftype |= SANS; # Sans Serif
925 if ($resftype == 0) {
926 $resftype = $ftypes{default};
929 # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
930 if ($resftype & FRAKTUR) {
931 $resftype &= ~(SANS|SERIF|SCRIPT);
933 elsif ($resftype & SCRIPT) {
934 $resftype &= ~(SANS|SERIF);
936 elsif ($resftype & SANS) {
940 for (my $i = 1; $i < 513; $i *= 2) {
941 if ($resftype & $i) {
942 push(@ft, $ftypes{$i});
945 return(join(',', @ft));
950 my ($fontname, $style) = @_;
952 for my $info ($style, $fontname) {
953 for my $key (keys %weights) {
954 next if ($key !~ /^\d+$/);
955 my $val = $weights{$key};
956 if ($info =~ /\b$val\b/i) {
966 my ($fontname, $style) = @_;
968 for my $key (keys %widths) {
969 next if ($key !~ /^\d+$/);
970 for my $info ($style, $fontname) {
971 if ($info =~ /\b$widths{$key}\b/i) {
972 return($widths{$key});
974 if ($info =~ /\bRegular\b/) {
975 if (!defined($result)) {
976 $result = $widths{100};
986 my ($fontname, $style) = @_;
987 for my $key (keys %slants) {
988 next if ($key !~ /^\d+$/);
989 if ($style =~ /\b$slants{$key}\b/i) {
990 return($slants{$key});
998 my ($fontname, $style) = @_;
999 for my $key (keys %spacings) {
1000 next if ($key !~ /^\d+$/);
1001 if ($style =~ /\b$spacings{$key}\b/i) {
1002 return($spacings{$key});
1005 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
1006 return($spacings{100}); # Mono
1015 my ($fontname, $rCapability) = @_;
1017 return 1 if ($fontname =~ /math/i);
1018 for my $cap (@{$rCapability}) {
1019 return 1 if ($cap eq "math");
1024 sub getproperties($$$$)
1026 my ($l, $fontname, $style, $rerrors) = @_;
1027 my $newstyle = &correctstyle($style);
1028 my $newfam = &correctstyle($fontname);
1029 my @properties = ();
1031 for my $txt (qw(ftype weight width slant spacing)) {
1033 eval("\$map = " . '\%' . $txt . 's');
1034 eval('$rget = \&' . "get$txt");
1035 my $val2 = getsinglevalue($l, $txt, $map);
1036 my $val1 = $rget->($newfam, $newstyle);
1038 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
1039 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/i)){
1040 # style overrides weight and slant
1041 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
1044 elsif ($newfam =~ /$val1/) {
1045 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
1049 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
1053 elsif (! defined($val2)) {
1059 if (defined($val)) {
1060 push(@properties, &addTxt($txt,$val));
1063 if (defined($map->{"default"})) {
1064 push(@properties, &addTxt($txt,$map->{"default"}));
1067 push(@{$rerrors}, "Undefined value for $txt");
1071 return(join(' ', @properties));
1077 $style =~ s/^\s*\d+\s*//;
1078 $style =~ s/\s*\d+$//;
1079 $style =~ s/italic/ Italic/i;
1080 $style =~ s/oblique/ Oblique/i;
1081 $style =~ s/[\-_]/ /g;
1082 $style =~ s/\breg\b/Regular/i;
1083 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
1084 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
1085 $style =~ s/medium/Medium /i;
1086 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
1087 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
1088 $style =~ s/\bmed\b/Medium /i;
1089 $style =~ s/\bex(pd|t)\b/Expanded/i;
1090 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
1091 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
1092 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
1093 $style =~ s/[sd]emi ?light/SemiLight/i;
1094 $style =~ s/\b[sd]emi\b/SemiBold/i;
1095 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
1096 $style =~ s/light/Light /i;
1097 $style =~ s/\blt\b/Light /i;
1098 $style =~ s/(ultra|extra) ?(light|lt)/ExtraLight /i;
1099 $style =~ s/\bheavy\b/Extrabold/i;
1100 $style =~ s/\bhairline\b/Extralight/i;
1101 $style =~ s/\bcond\b/Condensed/i;
1102 $style =~ s/(roman)?slanted/ Italic/i;
1103 $style =~ s/\bslant\b/Italic/i;
1104 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
1105 $style =~ s/w3 mono/Dual/i;
1106 $style =~ s/Regul[ea]r/Regular/i;
1107 $style =~ s/Megablack/ExtraBlack/i;
1113 # return list of unicode values of the input string
1114 #Allow input of intervals (e.g. 'a-z')
1115 sub decimalUnicode($)
1119 # Convert to unicode chars first
1120 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
1121 my ($prev, $d, $post) = ($1, $2, $3);
1122 if ($d =~ /^0?x(.+)$/) {
1125 my $chr = encode('utf-8', chr($d));
1126 $a = $prev . $chr . $post;
1128 # $a is now a string of unicode chars
1129 my $u = decode('utf-8', $a);
1130 my @a = split(//, $u);
1134 if ($x eq '-') { # Interval
1138 if ($interval && defined($start)) {
1139 if (ord($x) < $start) {
1140 for (my $i = $start - 1; $i >= ord($x); $i--) {
1145 for (my $i = $start + 1; $i <= ord($x); $i++) {
1161 # check if the glyph-values in interval @{$ri} are contained
1162 # in one of the (sorted) intervals
1166 # ...re0..........re1...
1167 # ......start..end......
1168 my ($ri, $rList) = @_;
1169 my $start = $ri->[0];
1172 for my $re (@{$rList}) {
1173 next if ($re->[1] < $start);
1174 # now we found a possible matching interval
1175 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1181 sub sprintIntervalls($)
1185 for my $rE (@{$rList}) {
1186 if ($rE->[0] != $rE->[1]) {
1187 push(@out, $rE->[0] . '-' . $rE->[1]);
1190 push(@out, $rE->[0]);
1193 return join(',', @out);
1196 sub buildFontName($$)
1198 my ($family, $style) = @_;
1201 $style =~ s/\\040//;
1202 $family =~ s/\\040/\-/;
1203 $family =~ s/\bcond\b/Condensed/i;
1204 $family =~ s/\bblk\b/Black/i;
1205 $family =~ s/\bsembd\b/SemiBold/i;
1206 $family =~ s/\bsemcond\b/SemiCondensed/i;
1207 $family =~ s/\bextcond\b/ExtraCondensed/i;
1208 $family =~ s/\bextbd\b/ExtraBold/i;
1209 $family =~ s/\bextlt\b/ExtraLight/i;
1210 $family =~ s/\bmed\b/Medium/i;
1212 # Split the family name at the border lowercase <-> uppercase characters
1213 # except if family starts with "TeX" or "DejaVu", etc
1214 if ($family =~ s/^((La|cw|PL)?TeX|DejaVu|MarVoSym|PL)//) {
1216 if ($family =~ /^[A-Z]/) {
1221 if ($family =~ /^([A-Z]*[a-z]+)([A-Z]\w+)\b(.*)$/) {
1222 $family = $1 . splitatlU($2) . $3;
1224 $family =~ s/^Ant Polt\b/Antykwa Poltawskiego/;
1225 $family =~ s/\b(Semi|Extra) (Bold|Condensed|Expanded|Light)\b/$1$2/;
1226 $family = $prefix . $family;
1227 my @style = &splitStyle($style);
1228 for my $st (@style) {
1230 if ($family !~ s/$st/$st/i) {
1234 # check if $st in $family starts with ' '
1235 $family =~ s/(\w)$st/$1 $st/i;
1239 return($result, join(' ', @style));
1242 # split text at change from lower case to upper case
1246 if ($txt =~ /^([A-Z]+[a-z]*)(.*)$/) {
1247 if (defined($mapShortcuts{$1})) {
1248 return(" " . $mapShortcuts{$1} . splitatlU($2));
1251 return(" $1" . splitatlU($2));
1259 my @in = split(/[- ]/, $_[0]);
1263 while ($en =~ s/^([A-Z][a-z]+)//) {
1265 if ($found =~ /^(Semi|Extra)$/) {
1269 elsif (defined($mapShortcuts{$found})) {
1270 $found = $mapShortcuts{$found};
1272 push(@result, "$prefix$found");
1276 push(@result, "$prefix$en");