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/[\/\\]?[^\/\\]+$//;
50 sub extractlist($$$); # my ($l, $islang, $txt, $rres) = @_;
52 sub getVal($$$$); # my ($l, $txtval, $txtlang, $combine) = @_;
53 sub getproperties($$$$);
56 sub decimalUnicode($);
58 sub sprintIntervalls($);
59 sub buildFontName($$);
60 sub splitatlU($); # split text at change from lower case to upper case
63 # Following fields for a parameter can be defined:
64 # fieldname: Name of entry in %options
65 # type: [:=][sif], ':' = optional, '=' = required, 's' = string, 'i' = integer, 'f' = float
66 # alias: reference to a list of aliases e.g. ["alias1", "alias2", ... ]
67 # listsep: Separator for multiple data
68 # comment: Parameter description
70 # help + verbose already handled in 'GetOptions'
72 {fieldname => "FontName", listsep => ',',
73 type => "=s", alias => ["name"],
74 comment => "Select font-names matching these (comma separated) regexes"},],
76 {fieldname => "NFontName",
77 type => "=s", listsep => ',',
78 comment => "Select font-names NOT matching these (comma separated) regexes"},],
80 {fieldname => "Property",
81 type => "=s", listsep => ',',
82 comment => "Select fonts with properties matching these (comma separated) regexes"},],
84 {fieldname => "NProperty",
85 type => "=s", listsep => ',',
86 comment => "Select fonts with properties NOT matching these (comma separated) regexes"},],
88 {fieldname => "Scripts",
89 type => "=s", listsep => ',',
90 comment => "Select fonts with scripts matching these (comma separated) regexes"},],
92 {fieldname => "NScripts",
93 type => "=s", listsep => ',',
94 comment => "Select fonts with scripts NOT matching these (comma separated) regexes"},],
97 comment => "Select fonts probably containing math glyphs"},],
99 {fieldname => "Contains", alias => ["contains"],
100 type => "=s", listsep => ',',
101 comment => "Select fonts containing all these (possibly comma separated) glyphs",
102 comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
104 {fieldname => "NContains",
105 type => "=s", listsep => ',',
106 comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
107 comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
109 {fieldname => "Lang",
110 type => "=s", alias=>["lang"],
111 comment => "Comma separated list of desired languages"},],
113 {fieldname => "PrintCharset", alias => ["printcharset"],
114 comment => "Print intervals of supported unicode character values"},],
116 {fieldname => "PrintLangs", alias => ["printlangs"],
117 comment => "Print supported languages"},],
119 {fieldname => "PrintProperties", alias => ["printproperties"],
120 comment => "Print properties from weight, slant and width"},],
122 {fieldname => "PrintScripts", alias => ["printscripts"],
123 comment => "Print supported scripts"},],
125 {fieldname => "PrintFiles", alias => ["printfiles"],
126 comment => "Print font file names"},],
128 {fieldname => "PrintWarnings",
129 comment => "Print warnings about discarded/overwritten fonts, conflicting styles"},],
131 my %options = %{&handleOptions(\@optionsDef)};
133 $options{Lang} = "" if (! defined($options{Lang}));
135 #############################################################
137 "Cond" => "Condensed",
138 "Expd" => "Expanded",
145 my @langs = split(',', $options{Lang});
146 for my $lg (@langs) {
147 $lg = &convertlang($lg);
150 for my $charFld ("Contains", "NContains") {
151 if (defined($options{$charFld})) {
152 my %glyphs = (); # To ignore duplicates
153 for my $a1 (@{$options{$charFld}}) {
154 for my $e (decimalUnicode($a1)) {
159 my @glyphs = sort {$a <=> $b;} keys %glyphs;
161 # $options{$charFld} no longer needed, so use it for unicode-point intervalls
162 $options{$charFld} = [];
163 my ($first, $last) = (undef, undef);
164 for my $i (@glyphs) {
165 if (! defined($last)) {
174 push(@{$options{$charFld}}, [$first, $last]);
178 if (defined($last)) {
179 push(@{$options{$charFld}}, [$first, $last]);
181 if (exists($options{verbose})) {
182 if ($charFld eq "Contains") {
183 print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
186 print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
193 if (defined($langs[0])) {
194 $cmd .= " :lang=" . join(',', @langs);
197 my $format = "foundry=\"%{foundry}\"" .
198 " postscriptname=\"%{postscriptname}\"" .
199 " fn=\"%{fullname}\" fnl=\"%{fullnamelang}\"" .
200 " family=\"%{family}\" flang=\"%{familylang}\" " .
201 " style=\"%{style}\" stylelang=\"%{stylelang}\"";
203 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
204 $format .= " script=\"%{capability}\"";
206 if (exists($options{PrintLangs}) || defined($langs[0])) {
207 $format .= " lang=\"%{lang}\"";
209 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
210 $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
212 if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
213 $format .= " charset=\"%{charset}\"";
215 $format .= " file=\"%{file}\" abcd\\n";
216 $cmd .= " -f '$format'";
222 # using '()' to prevent the initializer to take
223 # the key as a string. (Constants in perl _are_ functions without argument)
226 SCRIPT() => "Script",
227 FRAKTUR() => "Fraktur",
228 DOUBLESTROKE() => "DoubleStroke",
230 INITIALS() => "Initials",
231 SYMBOL() => "Symbol",
232 SMALLCAP() => "SmallCap",
258 50 => "Ultracondensed",
259 63 => "Extracondensed",
261 87 => "Semicondensed",
263 113 => "Semiexpanded",
265 150 => "Extraexpanded",
266 200 => "Ultraexpanded",
274 "default" => "Proportional",
277 # Build reverse mappings, (not needed yet)
278 for my $txt (qw(ftypes weights slants widths spacings)) {
280 eval "\$map = \\%$txt";
281 for my $key (keys %{$map}) {
282 next if ($key !~ /^\d+$/);
283 my $value = lc($map->{$key});
284 $map->{"r"}->{$value} = $key;
291 my %collectedfonts = ();
293 otf => 0, # type 2, opentype CFF (Compact Font Format)
294 ttc => 1.1, # type 1 (True Type font Collection)
295 ttf => 1.2, # type 1 (True Type Font)
296 woff=> 1.3, # type 1 (Web Open Font Format)
297 t1 => 1.4, # type 1 (postscript)
298 pfb => 1.5, # type 1 (Printer Font Binary)
299 pfa => 1.6, # type 1 (Printer Font Ascii)
300 pfm => 2, # requires associated .pfb file
301 pcf => 5, # Bitmap (Packaged Collaboration Files)?
306 # some extra serif fonts
308 "g" => qr/^gfs ?(didot)/i,
310 # list of regexes for known sans serif fonts
312 "value" => SANS, # Sans serif
313 "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,
314 "b" => qr/^b(abel ?stone ?modern|aekmuk|alker|altar|andal|angwool|arbatrick|aveuse|bold|dxsfm|ebas|erenika|eteckna|euron|iometric|iting|lue|m ?hanna)/i,
315 "c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|harles|hilanka|hinese ?rocks|hivo|mu bright|omfortaa|omi[cx]|oolvetica|ortoba|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
316 "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
317 "e" => qr/^(electron|engebrechtre)/i,
318 "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
319 "g" => qr/^g(ardiner|aruda|fs ?neo|illius|ood ?times|ranada|raph|uanine|unplay)/i,
320 "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
321 "i" => qr/^(ibm ?(plex ?mono|3270)|ikarius|inconsolata|induni.?h|iwona)/i,
322 "j" => qr/^j(ara|ura|s ?math.?bbold)/i,
323 "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kurier|kustom)/i,
324 "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
325 "m" => qr/^m(\+ |anchu|anjari|arcellus|ashq|eera|etal|igmix|igu|ikachan|intspirit|iriam ?clm|isaki|ona|onlam|ono(fonto|id|isome|noki)|ontserrat|otoyal|ukti|usica)/i,
326 "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
327 "o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
328 "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
329 "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
330 "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
331 "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
332 "t" => qr/^(tarablus|teen|texgyre(adventor|heros)|tiresias|trebuchet|tscu|tuffy)/i,
333 "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,
334 "v" => qr/^(veranda|vn ?urwclassico)/i,
335 "w" => qr/^(waree)/i,
336 "y" => qr/^(yanone)/i,
337 "z" => qr/^(zekton|zero)/i,
340 "value" => SCRIPT, # Script
341 "a" => qr/^a(becedario|ir ?cut|ugie|uriocus ?kalligraph)/i,
342 "b" => qr/^b(reip|rush ?script)/i,
343 "c" => qr/^(chancery)/i,
344 "d" => qr/^(dancing)/i,
345 "e" => qr/^(elegante)/i,
346 "f" => qr/^femkeklaver/i,
347 "j" => qr/^jsmath.?(rsfs)/i,
348 "k" => qr/^(kaushan|karumbi|kristi)/i,
349 "m" => qr/^(math ?jax.?script|miama)/i,
350 "n" => qr/^(nanum (brush|pen) script)/i,
352 "q" => qr/^qt( ?black ?forest|arabian|boulevard|brush ?stroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
353 "r" => qr/^((romande.*|ruf)script|rsfs)/i,
354 "t" => qr/^typo ?script/i,
355 "u" => qr/^u(n ?pilgi|rw ?chancery|kij ?(jelliy|moy|qolyazma ?(tez|yantu)))/i,
359 "value" => FRAKTUR, # Fraktur
360 "b" => qr/^boondox ?fraktur/i,
362 "j" => qr/^(jsmath.?euf)/i,
363 "m" => qr/^(missaali)/i,
364 "o" => qr/^(oldania)/i,
365 "q" => qr/^qt(blackforest|cloisteredmonk|dublinirish|fraktur|heidelbergtype|(lino|london) ?scroll)/i,
366 "u" => qr/^ukij ?(kufi ?tar|mejnun ?reg)/i,
370 "value" => FANCY, # Fancy
371 "a" => qr/^a(bandoned|bberancy|driator|irmole|lmonte (snow|woodgrain)|nalecta|ni|nklepants|nn ?stone|oyagi|rt ?nouveau ?caps|stron|xaxa)/i,
372 "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,
373 "c" => qr/^c(retino|msy|abin ?sketch|arbon|arolingan|harles|hicken|hilanka|hr\d)/i,
375 "e" => qr/^electorate/i,
376 "f" => qr/^frederika/i,
377 "g" => qr/^(gfs.?theo)/i,
378 "j" => qr/^jsmath.cmsy/i,
379 "k" => qr/^keter|kicking|kredit|kouzan/i,
381 "q" => qr/^qtcaslan ?open/i,
382 "u" => qr/^u(kij ?(saet|tiken)|nion ?city)/i,
383 "v" => qr/^vectroid/i,
387 "value" => INITIALS, # Initials
388 "c" => qr/^carrick/i,
389 "e" => qr/^(eb.?garamond.?init)/i,
390 "t" => qr/^typographer/i,
391 "y" => qr/^(yinit)/i,
395 "value" => SYMBOL, # Symbol
396 "a" => qr/^a(cademicons|lblant|lianna|mar|nka|rb?\d|rchaic|rrow|rs|rt[mt]|ssy(rb\d+)?\b|miri ?quran|mit\b)/i,
397 "b" => qr/^b(aby ?jeepers|bding|euron|guq|lex|lsy|oondox ?upr|ullets|urma)/i,
398 "c" => qr/^c(aladings|cicons|hess|msy|mex|apacitor)/i,
399 "d" => qr/^(dingbats|drmsym|d05)/i,
400 "e" => qr/^e(lusiveicons|mmentaler|moji|sint|uterpe)/i,
401 "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
402 "g" => qr/^(gan.?clm|gfs.?(baskerville|gazis|olga|porson|solomos|(bodoni|didot).?classic|complutum))/i,
403 "h" => qr/^h(ots|ershey)/i,
404 "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
405 "l" => qr/^l(cmsy|msam)/i,
406 "m" => qr/^(marvosym|material|msam|msbm)/i,
407 "n" => qr/^(noto.*(emoji|brahmi))/i,
408 "o" => qr/^(octicons)/i,
410 "q" => qr/^(qtding ?bits)/i,
411 "s" => qr/^s(kak|tmary|s?msam|tix ?math)/i,
412 "t" => qr/^(typicons|twemoji)/i,
413 "u" => qr/^ukij ?(imaret|orxun|tughra)/i,
414 "w" => qr/^w(ebdings|asy|elfare ?brat)/i,
417 my %smallcapFonts = (
418 "value" => SMALLCAP | SERIF,
419 "c" => qr/^cs[ct]sc\d/i,
420 "d" => qr/^drm(it)?sc\d/i,
421 "f" => qr/^fetamont.?script/i,
422 "n" => qr/^newtxb?ttsc/i,
423 "s" => qr/^(screengem|sf.?kp.?sc)/i,
424 "t" => qr/^t1?xb?ttsc/i,
425 "v" => qr/^vn ?cccsc\d/i,
428 if (open(FI, "$cmd |")) {
429 NXTLINE: while (my $l = <FI>) {
431 while ($l !~ /abcd$/) {
437 if ($l =~ /file=\"([^\"]+)\"/) {
439 #next if ($file !~ /\.(otf|ttf|pfa|pfb|pcf|ttc)$/i);
440 if ($file !~ /\.([a-z0-9]{2,5})$/i) {
441 print "Unhandled extension for file $file\n";
445 if (! defined($fontpriority{$fonttype})) {
446 print "Added extension $fonttype for file $file\n";
447 $fontpriority{$fonttype} = $nexttype;
452 if ($l =~ / lang=\"([^\"]+)\"/) {
453 my @ll = split(/\|/, $1);
455 $usedlangs{&convertlang($lx)} = 1;
459 for my $lang (@langs) {
460 next NXTLINE if (! defined($usedlangs{$lang}));
462 my ($fullname, $fuidx) = &getVal($l, "fn", "fnl", -1);
463 my ($style, $fsidx) = &getVal($l, "style", "stylelang", $fuidx);
464 $style =~ s/^\\040//;
465 my ($family, $faidx) = &getVal($l, "family", "flang", $fsidx);
467 my $postscriptname = "";
468 if ($l =~ /postscriptname=\"([^\"]+)\"/) {
469 $postscriptname = $1;
472 ($fontname, $style) = &buildFontName($family, $style);
473 if (defined($options{NFontName})) {
474 for my $fn (@{$options{NFontName}}) {
475 next NXTLINE if ($fontname =~ /$fn/i);
478 if (defined($options{FontName})) {
479 for my $fn (@{$options{FontName}}) {
480 next NXTLINE if ($fontname !~ /$fn/i);
484 if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
485 if ($l =~ / charset=\"([^\"]+)\"/) {
486 my @list = split(/\s+/, $1);
488 my ($l, $h) = split('-', $e);
489 $h = $l if (! defined($h));
490 push(@charlist, [hex($l), hex($h)]);
493 if (defined($options{Contains})) {
494 for my $g (@{$options{Contains}}) {
495 next NXTLINE if (! contains($g, \@charlist));
498 if (defined($options{NContains})) {
499 for my $g (@{$options{NContains}}) {
500 # Ignore if ANY char exist in @charlist
501 for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
502 next NXTLINE if (contains([$i,$i], \@charlist));
509 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
510 my $properties = getproperties($l, $fontname, $style, \@errors);
511 if (defined($options{Property})) {
512 for my $pn (@{$options{Property}}) {
513 next NXTLINE if ($properties !~ /$pn/i);
516 if (defined($options{NProperty})) {
517 for my $pn (@{$options{NProperty}}) {
518 next NXTLINE if ($properties =~ /$pn/i);
521 if (exists($options{PrintProperties})) {
522 $props .= " ($properties)";
526 if (exists($options{PrintLangs})) {
527 $props .= '(' . join(',', sort keys %usedlangs) . ')';
529 if (exists($options{PrintCharset})) {
530 $props .= '(' . &sprintIntervalls(\@charlist) . ')';
532 if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
535 if ($l =~ / script=\"([^\"]+)\"/) {
536 @scripts = split(/\s+/, $1);
537 for my $ent (@scripts) {
538 $ent =~ s/^\s*otlayout://;
541 $scripts = join(',', @scripts);
543 if (exists($options{Math})) {
544 next NXTLINE if (! &ismathfont($fontname,\@scripts));
546 if (exists($options{PrintScripts})) {
547 $props .= "($scripts)";
549 if (!defined($scripts[0])) {
550 # No script defined in font, so check only $options{Scripts}
551 next NXTLINE if (defined($options{Scripts}));
554 if (defined($options{Scripts})) {
555 for my $s (@{$options{Scripts}}) {
556 next NXTLINE if ($scripts !~ /$s/i);
559 if (defined($options{NScripts})) {
560 for my $s (@{$options{NScripts}}) {
561 next NXTLINE if ($scripts =~ /$s/i);
567 if ($l =~ /foundry=\"([^\"]+)\"/) {
569 $foundry =~ s/^\s+//;
570 $foundry =~ s/\s+$//;
572 if (defined($collectedfonts{$fontname}->{$foundry}->{errors})) {
573 # Apparently not the first one, so add some info
574 my $oldfonttype = $collectedfonts{$fontname}->{$foundry}->{fonttype};
575 if (defined($errors[0])) {
576 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, @errors);
578 if ($fontpriority{$oldfonttype} > $fontpriority{$fonttype}) {
579 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: overwriting old info of file: " . $collectedfonts{$fontname}->{$foundry}->{file});
582 push(@{$collectedfonts{$fontname}->{$foundry}->{errors}}, "Warning: discarding new info from file: $file");
587 $collectedfonts{$fontname}->{$foundry}->{errors} = \@errors;
589 $collectedfonts{$fontname}->{$foundry}->{props} = $props;
590 $collectedfonts{$fontname}->{$foundry}->{file} = $file;
591 $collectedfonts{$fontname}->{$foundry}->{fonttype} = $fonttype;
596 for my $fontname (sort keys %collectedfonts) {
597 my @foundries = sort keys %{$collectedfonts{$fontname}};
598 my $printfoundries = 0;
599 if (defined($foundries[1])) {
602 for my $foundry (@foundries) {
603 if (exists($options{PrintWarnings})) {
604 for my $err (@{$collectedfonts{$fontname}->{$foundry}->{errors}}) {
608 my $fn = "Font : $fontname";
609 if ($printfoundries && ($foundry ne "")) {
610 $fn .= " \[$foundry\]";
613 print $collectedfonts{$fontname}->{$foundry}->{props};
614 if (exists($options{PrintFiles})) {
615 print ": " . $collectedfonts{$fontname}->{$foundry}->{file} . "\n";
624 #################################################################################
628 if ($ilang =~ /^\s*([a-z]+)([\-_]([a-z]+))?\s*$/i) {
629 my ($x, $y) = ($1, $3);
631 $ilang = lc($x) . '-' . lc($y);
642 my ($l, $islang, $txt, $rres) = @_;
644 if ($l =~ /$txt=\"([^\"]+)\"/) {
645 @res = split(',', $1);
648 $lg = &convertlang($lg);
657 my ($lang, $rlangs) = @_;
660 for (my $i = 0; defined($rlangs->[$i]); $i++) {
661 if ($rlangs->[$i] eq $lang) {
670 my ($l, $txtval, $txtlang, $startentry) = @_;
673 &extractlist($l, 0, $txtval, \@values);
674 return("", -1) if (! defined($values[0]));
675 &extractlist($l, 1, $txtlang, \@langs);
676 my $i = &getIndexes("en", \@langs);
678 my $actualentry = -1;
681 if (defined($values[$k])) {
683 if ($startentry < 0) {
684 if (length($values[$k]) > length($res)) {
686 $usedentry = $actualentry;
689 elsif ($actualentry == $startentry) {
691 $usedentry = $actualentry;
695 # select the longest entry if possible
696 if (length($values[$k]) > length($res)) {
698 $usedentry = $actualentry;
703 return($values[0], -1) if ($res eq "");
704 return($res, $usedentry);
707 sub getsinglevalue($$$)
709 my ($l, $txt, $rMap, $rget) = @_;
711 if ($l =~ / $txt=(\d+)/) {
713 # Search for nearest value to $val
714 if (defined($rMap->{$val})) {
715 return($rMap->{$val});
719 for my $key (keys %{$rMap}) {
720 next if ($key !~ /^\d+$/);
721 my $diff = abs($key - $val);
726 elsif ($diff == $minv) {
732 if (! defined($rMap->{$maxv})) {
733 print "ERROR2: txt=$txt, val=$val\n";
737 return($rMap->{$maxv} . "+$minv");
740 return($rMap->{$maxv} . "-$minv");
750 my ($txt, $val) = @_;
751 return("$txt($val)");
756 my ($fontname, $style) = @_;
758 if ($fontname =~ /(sans)[-_ ]?(serif)?/i) {
761 elsif ($fontname =~ /gothic|dotum|gulim/i) {
762 if ($fontname =~ /bisrat gothic/i) {
765 elsif ($fontname !~ /hershey/i) {
769 elsif ($fontname =~ /^(js ?math.?)?bbold|msbm|^(ds(rom|serif|ss))|DoubleStruck/i) {
770 $resftype |= DOUBLESTROKE; # Double stroke (math font)
772 if ($fontname =~ /serif|times|mincho|batang/i) {
773 $resftype |= SERIF; # Serif
775 if ($fontname =~ /initial(s|en)/i) {
776 $resftype |= INITIALS;
777 if ($fontname =~ /^linux ?libertine/i) {
781 if ($fontname =~ /participants/i) {
782 $resftype |= SANS|FANCY;
784 if ($fontname =~ /symbol|cherokee/i) {
785 if ($fontname !~ /^(symbola|asap)/i) {
787 if ($fontname =~ /^(ams ?math|computer modern bright msb)/i) {
788 $resftype |= DOUBLESTROKE | SERIF;
792 if ($fontname =~ /callig/i) {
795 if ($fontname =~ /\bS(mall)?C(aps)\b/i) {
796 if ($fontname !~ /^noto/i) {
797 $resftype |= SMALLCAP|SERIF;
800 # Now check for fonts without a hint in font name
801 if ($fontname =~ /^([a-z])/i) {
803 # check the mutual exclusive first
804 for my $rFonts (\%fraktFonts, \%scriptFonts, \%sansFonts, \%serifFonts) {
805 if (defined($rFonts->{$key})) {
806 if ($fontname =~ $rFonts->{$key}) {
807 $resftype |= $rFonts->{"value"};
812 for my $rFonts (\%fancyFonts, \%initialFonts, \%symbolFonts, \%smallcapFonts) {
813 if (defined($rFonts->{$key})) {
814 if ($fontname =~ $rFonts->{$key}) {
815 $resftype |= $rFonts->{"value"};
820 if ("$fontname" =~ /^bpg/i) {
821 if ("$fontname" =~ /bpg (courier gpl|elite|serif)/i) {
822 $resftype |= SERIF; # Serif
825 $resftype |= SANS; # Sans Serif
828 elsif ("$fontname" =~ /^dustismo/i) {
829 if ("$fontname" =~ /^dustismo roman/i) {
830 $resftype |= SERIF; # Serif
833 $resftype |= SANS; # Sans Serif
836 elsif ("$fontname" =~ /^go\b/i) {
837 if ("$fontname" =~ /^go mono/i) {
838 $resftype |= SERIF; # Serif
841 $resftype |= SANS; # Sans Serif
846 if ($resftype == 0) {
847 $resftype = $ftypes{default};
850 # fonts SANS, SERIF, SCRIPT and FRAKTUR are mutualy exclusive
851 if ($resftype & FRAKTUR) {
852 $resftype &= ~(SANS|SERIF|SCRIPT);
854 elsif ($resftype & SCRIPT) {
855 $resftype &= ~(SANS|SERIF);
857 elsif ($resftype & SANS) {
861 for (my $i = 1; $i < 513; $i *= 2) {
862 if ($resftype & $i) {
863 push(@ft, $ftypes{$i});
866 return(join(',', @ft));
871 my ($fontname, $style) = @_;
873 for my $info ($style, $fontname) {
874 for my $key (keys %weights) {
875 next if ($key !~ /^\d+$/);
876 my $val = $weights{$key};
877 if ($info =~ /\b$val\b/i) {
887 my ($fontname, $style) = @_;
889 for my $key (keys %widths) {
890 next if ($key !~ /^\d+$/);
891 for my $info ($style, $fontname) {
892 if ($info =~ /\b$widths{$key}\b/i) {
893 return($widths{$key});
895 if ($info =~ /\bRegular\b/) {
896 if (!defined($result)) {
897 $result = $widths{100};
907 my ($fontname, $style) = @_;
908 for my $key (keys %slants) {
909 next if ($key !~ /^\d+$/);
910 if ($style =~ /\b$slants{$key}\b/i) {
911 return($slants{$key});
919 my ($fontname, $style) = @_;
920 for my $key (keys %spacings) {
921 next if ($key !~ /^\d+$/);
922 if ($style =~ /\b$spacings{$key}\b/i) {
923 return($spacings{$key});
926 if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
927 return($spacings{100}); # Mono
936 my ($fontname, $rCapability) = @_;
938 return 1 if ($fontname =~ /math/i);
939 for my $cap (@{$rCapability}) {
940 return 1 if ($cap eq "math");
945 sub getproperties($$$$)
947 my ($l, $fontname, $style, $rerrors) = @_;
948 my $newstyle = &correctstyle($style);
949 my $newfam = &correctstyle($fontname);
952 for my $txt (qw(ftype weight width slant spacing)) {
954 eval("\$map = " . '\%' . $txt . 's');
955 eval('$rget = \&' . "get$txt");
956 my $val2 = getsinglevalue($l, $txt, $map);
957 my $val1 = $rget->($newfam, $newstyle);
959 if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
960 if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/i)){
961 # style overrides weight and slant
962 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
965 elsif ($newfam =~ /$val1/) {
966 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
970 push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
974 elsif (! defined($val2)) {
981 push(@properties, &addTxt($txt,$val));
984 if (defined($map->{"default"})) {
985 push(@properties, &addTxt($txt,$map->{"default"}));
988 push(@{$rerrors}, "Undefined value for $txt");
992 return(join(' ', @properties));
998 $style =~ s/^\s*\d+\s*//;
999 $style =~ s/\s*\d+$//;
1000 $style =~ s/italic/ Italic/i;
1001 $style =~ s/oblique/ Oblique/i;
1002 $style =~ s/[\-_]/ /g;
1003 $style =~ s/\breg\b/Regular/i;
1004 $style =~ s/\bregita(lic)?\b/Regular Italic/i;
1005 $style =~ s/\bregobl(ique)?\b/Regular Oblique/i;
1006 $style =~ s/medium/Medium /i;
1007 $style =~ s/\bmedita(lic)?\b/Medium Italic/i;
1008 $style =~ s/\bmedobl(ique)?\b/Medium Oblique/i;
1009 $style =~ s/\bmed\b/Medium /i;
1010 $style =~ s/\bdemi\b/SemiBold/i;
1011 $style =~ s/\bex(pd|t)\b/Expanded/i;
1012 $style =~ s/semi ?cond(ensed)?/SemiCondensed/i;
1013 $style =~ s/[sd]emi ?(bold|bd|bol)/SemiBold/i;
1014 $style =~ s/semi ?(expanded|extended|expd)/SemiExpanded/i;
1015 $style =~ s/[sd]emi ?light/SemiLight/i;
1016 $style =~ s/ultra ?(expanded|extended|expd)/UltraExpanded/i;
1017 $style =~ s/light/Light /i;
1018 $style =~ s/\blt\b/Light /i;
1019 $style =~ s/(ultra|extra) ?(light|lt)/ExtraLight /i;
1020 $style =~ s/\bheavy\b/Extrabold/i;
1021 $style =~ s/\bhairline\b/Extralight/i;
1022 $style =~ s/\bcond\b/Condensed/i;
1023 $style =~ s/(roman)?slanted/ Italic/i;
1024 $style =~ s/\bslant\b/Italic/i;
1025 $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
1026 $style =~ s/w3 mono/Dual/i;
1027 $style =~ s/Regul[ea]r/Regular/i;
1028 $style =~ s/Megablack/ExtraBlack/i;
1034 # return list of unicode values of the input string
1035 #Allow input of intervals (e.g. 'a-z')
1036 sub decimalUnicode($)
1040 # Convert to unicode chars first
1041 while ($a =~ /^(.*)u\+(0?x[\da-f]+|\d+)(.*)$/i) {
1042 my ($prev, $d, $post) = ($1, $2, $3);
1043 if ($d =~ /^0?x(.+)$/) {
1046 my $chr = encode('utf-8', chr($d));
1047 $a = $prev . $chr . $post;
1049 # $a is now a string of unicode chars
1050 my $u = decode('utf-8', $a);
1051 my @a = split(//, $u);
1055 if ($x eq '-') { # Interval
1059 if ($interval && defined($start)) {
1060 if (ord($x) < $start) {
1061 for (my $i = $start - 1; $i >= ord($x); $i--) {
1066 for (my $i = $start + 1; $i <= ord($x); $i++) {
1082 # check if the glyph-values in interval @{$ri} are contained
1083 # in one of the (sorted) intervals
1087 # ...re0..........re1...
1088 # ......start..end......
1089 my ($ri, $rList) = @_;
1090 my $start = $ri->[0];
1093 for my $re (@{$rList}) {
1094 next if ($re->[1] < $start);
1095 # now we found a possible matching interval
1096 return 1 if (($start >= $re->[0]) && ($end <= $re->[1]));
1102 sub sprintIntervalls($)
1106 for my $rE (@{$rList}) {
1107 if ($rE->[0] != $rE->[1]) {
1108 push(@out, $rE->[0] . '-' . $rE->[1]);
1111 push(@out, $rE->[0]);
1114 return join(',', @out);
1117 sub buildFontName($$)
1119 my ($family, $style) = @_;
1122 $style =~ s/\\040//;
1123 $family =~ s/\\040/\-/;
1124 $family =~ s/\bcond\b/Condensed/i;
1125 $family =~ s/\bblk\b/Black/i;
1126 $family =~ s/\bsembd\b/SemiBold/i;
1127 $family =~ s/\bsemcond\b/SemiCondensed/i;
1128 $family =~ s/\bextcond\b/ExtraCondensed/i;
1129 $family =~ s/\bextbd\b/ExtraBold/i;
1130 $family =~ s/\bextlt\b/ExtraLight/i;
1131 $family =~ s/\bmed\b/Medium/i;
1132 if ($family =~ /^([A-Z]*[a-z]+)([A-Z]\w+)\b(.*)$/) {
1133 $family = $1 . splitatlU($2) . $3;
1135 $family =~ s/^Ant Polt\b/Antykwa Poltawskiego/;
1136 $family =~ s/\b(Semi|Extra) (Bold|Condensed|Expanded|Light)\b/$1$2/;
1137 my @style = &splitStyle($style);
1138 for my $st (@style) {
1140 if ($family !~ s/$st/$st/i) {
1144 # check if $st in $family starts with ' '
1145 $family =~ s/(\w)$st/$1 $st/i;
1149 return($result, join(' ', @style));
1152 # split text at change from lower case to upper case
1156 if ($txt =~ /^([A-Z]+[a-z]*)(.*)$/) {
1157 if (defined($mapShortcuts{$1})) {
1158 return(" " . $mapShortcuts{$1} . splitatlU($2));
1161 return(" $1" . splitatlU($2));
1169 my @in = split(/[- ]/, $_[0]);
1173 while ($en =~ s/^([A-Z][a-z]+)//) {
1175 if ($found =~ /^(Semi|Extra)$/) {
1179 elsif (defined($mapShortcuts{$found})) {
1180 $found = $mapShortcuts{$found};
1182 push(@result, "$prefix$found");
1186 push(@result, "$prefix$en");