]> git.lyx.org Git - lyx.git/blobdiff - development/tools/listFontWithLang.pl
Add some localized (Russian) cliparts, by Yuriy
[lyx.git] / development / tools / listFontWithLang.pl
index 342e70e9f67e249f3dccb731b1f0cb66bd234a68..92901fcdc4b252e6a8ac595806b571763b8ef74b 100644 (file)
@@ -44,6 +44,7 @@ sub ismathfont($$);
 sub correctstyle($);
 sub decimalUnicode($);
 sub contains($$);
+sub sprintIntervalls($);
 
 # Following fields for a parameter can be defined:
 # fieldname:         Name of entry in %options
@@ -81,9 +82,15 @@ my @optionsDef = (
    {fieldname => "Math",
     comment => "Select fonts probably containing math glyphs"},],
   ["c",
-   {fieldname => "Contains",
+   {fieldname => "Contains",  alias => ["contains"],
     type => "=s", listsep => ',',
-    comment => "Select fonts containing all these (possibly comma separated) glyphs",}],
+    comment => "Select fonts containing all these (possibly comma separated) glyphs",
+    comment2 => "____example: -c=\"0-9,u+32-u+x7f\"",}],
+  ["nc",
+   {fieldname => "NContains",
+    type => "=s", listsep => ',',
+    comment => "Select fonts NOT containing any of these (possibly comma separated) glyphs",
+    comment2 => "____example: --nc=\"0-9,u+32-u+x7f\"",}],
   ["l",
    {fieldname => "Lang",
     type => "=s", alias=>["lang"],
@@ -118,35 +125,45 @@ for my $lg (@langs) {
   $lg = &convertlang($lg);
 }
 
-if (defined($options{Contains})) {
-  my %glyphs = ();         # To ignore duplicates
-  for my $a1 (@{$options{Contains}}) {
-    for my $e (decimalUnicode($a1)) {
-      $glyphs{$e} = 1;
+for my $charFld ("Contains", "NContains") {
+  if (defined($options{$charFld})) {
+    my %glyphs = ();         # To ignore duplicates
+    for my $a1 (@{$options{$charFld}}) {
+      for my $e (decimalUnicode($a1)) {
+        $glyphs{$e} = 1;
+      }
     }
-  }
-  # create intervalls
-  my @glyphs = sort {$a <=> $b;} keys %glyphs;
+    # create intervalls
+    my @glyphs = sort {$a <=> $b;} keys %glyphs;
 
-  # $options{Contains} no longer needed, so use it for unicode-point intervalls
-  $options{Contains} = [];
-  my ($first, $last) = (undef, undef);
-  for my $i (@glyphs) {
-    if (! defined($last)) {
+    # $options{$charFld} no longer needed, so use it for unicode-point intervalls
+    $options{$charFld} = [];
+    my ($first, $last) = (undef, undef);
+    for my $i (@glyphs) {
+      if (! defined($last)) {
+        $first = $i;
+        $last = $i;
+        next;
+      }
+      if ($i == $last+1) {
+        $last = $i;
+        next;
+      }
+      push(@{$options{$charFld}}, [$first, $last]);
       $first = $i;
       $last = $i;
-      next;
     }
-    if ($i == $last+1) {
-      $last = $i;
-      next;
+    if (defined($last)) {
+      push(@{$options{$charFld}}, [$first, $last]);
+    }
+    if (exists($options{verbose})) {
+      if ($charFld eq "Contains") {
+        print "Checking for unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
+      }
+      else {
+        print "Ignore if matching unicode-points: " . &sprintIntervalls($options{$charFld}) . "\n";
+      }
     }
-    push(@{$options{Contains}}, [$first, $last]);
-    $first = $i;
-    $last = $i;
-  }
-  if (defined($last)) {
-    push(@{$options{Contains}}, [$first, $last]);
   }
 }
 
@@ -161,7 +178,7 @@ my $format = "foundry=\"%{foundry}\"" .
     " family=\"%{family}\" flang=\"%{familylang}\" " .
     " style=\"%{style}\" stylelang=\"%{stylelang}\"";
 
-if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NSpripts}) || exists($options{Math})) {
+if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
   $format .= " script=\"%{capability}\"";
 }
 if (exists($options{PrintLangs}) || defined($langs[0])) {
@@ -170,7 +187,7 @@ if (exists($options{PrintLangs}) || defined($langs[0])) {
 if (exists($options{PrintProperties}) || defined($options{Property}) || defined($options{NProperty})) {
   $format .= " weight=%{weight} slant=%{slant} width=%{width} spacing=%{spacing}";
 }
-if (defined($options{Contains}) || exists($options{PrintCharset})) {
+if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
   $format .= " charset=\"%{charset}\"";
 }
 $format .= " file=\"%{file}\" abcd\\n";
@@ -260,9 +277,9 @@ my $nexttype = 6;
 # list of regexes for known sans serif fonts
 my %sansFonts = (
   "value" => 100,          # Sans serif
-  "a" => qr/^(arial|andika|angostura|anonymous|arab|aroania|arimo|asap)/i,
+  "a" => qr/^(aharoni|arial|andika|angostura|anonymous|arab|aroania|arimo|asap)/i,
   "b" => qr/^b(aekmuk|ebas|erenika|eteckna|euron|lue)/i,
-  "c" => qr/^c(abin|aliban|antarell|arbon|arlito|handas|hivo|mu bright|omfortaa|omic|oolvetica|ortoba|ousine|uprum|wtex(hei|yen)|yklop|ypro)/i,
+  "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,
   "d" => qr/^(d2coding|dimnah|dosis|dyuthi)/i,
   "e" => qr/^(electron|engebrechtre)/i,
   "f" => qr/^(fandolhei|fetamont|fira|font awesome 5|forgotten)/i,
@@ -270,12 +287,12 @@ my %sansFonts = (
   "h" => qr/^(hack|hani|haramain|harano|harmattan|hor\b)/i,
   "i" => qr/^(ibm plex|ikarius|inconsolata|induni.?h|iwona)/i,
   "j" => qr/^(jara|jura)/i,
-  "k" => qr/^(kalimati|kanji|karla|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|komatu|kurier)/i,
+  "k" => qr/^(kalimati|kanji|karla|karma|kayrawan|kenyan|keraleeyam|khalid|khmer [or]|kiloji|klaudia|ko[mn]atu|kurier|kustom)/i,
   "l" => qr/^l(aksaman|arabie|ato|eague|exend|exigulim|ibel|iberation|ibre franklin|ibris|inux biolinum|obster|ogix|ohit|oma)/i,
-  "m" => qr/^m(\+ |anchu|anjari|arcellus|ashq|eera|etal|igmix|igu|ikachan|intspirit|ona|onlam|ono(fonto|id|isome|noki)|ontserrat|otoyal|ukti|usica)/i,
+  "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,
   "n" => qr/^(nachlieli|nada|nafees|nagham|nanum(barunpen|square)|nice)/i,
   "o" => qr/^(ocr|okolaks|opendyslexic|ostorah|ouhud|over|oxygen)/i,
-  "p" => qr/^(padauk|padmaa|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
+  "p" => qr/^(padauk|pagul|paktype|pakenham|palladio|petra|phetsarath|play\b|poiret|port\b|primer\b|prociono|pt\b|purisa)/i,
   "q" => qr/^(qt(ancient|helvet|avanti|doghaus|eratype|eurotype|floraline|frank|fritz|future|greece|howard|letter|optimum)|quercus)/i,
   "r" => qr/^(rachana|radio\b|raleway|ricty|roboto|rosario)/i,
   "s" => qr/^(salem|samanata|sawasdee|shado|sharja|simple|sophia|soul|source|switzera)/i,
@@ -291,16 +308,18 @@ my %scriptFonts = (
   "c" => qr/^(chancery)/i,
   "d" => qr/^(dancing)/i,
   "e" => qr/^(elegante)/i,
-  "k" => qr/^(kaushan|karumbi)/i,
+  "j" => qr/^jsmath.?(rsfs)/i,
+  "k" => qr/^(kaushan|karumbi|kristi)/i,
   "m" => qr/^(mathjax_script|miama)/i,
   "n" => qr/^(nanum (brush|pen) script)/i,
   "q" => qr/^qt(arabian|boulevard|brushstroke|chancery|coronation|florencia|handwriting|linostroke|merry|pandora|slogan)/i,
-  "r" => qr/^(romande.*|ruf)script/i,
+  "r" => qr/^((romande.*|ruf)script|rsfs)/i,
   "u" => qr/^(un ?pilgi|urw ?chancery)/i,
 );
 
 my %fraktFonts = (
   "value" => 120,          # Fraktur
+  "e" => qr/^eufm/i,
   "j" => qr/^(jsmath.?euf)/i,
   "m" => qr/^(missaali)/i,
   "o" => qr/^(oldania)/i,
@@ -310,7 +329,10 @@ my %fraktFonts = (
 my %fancyFonts = (
   "value" => 130,          # Fancy
   "c" => qr/^(cretino)/i,
+  "d" => qr/^dseg/i,
+  "f" => qr/^frederika/i,
   "g" => qr/^(gfs.?theo)/i,
+  "k" => qr/^keter|kicking|kredit|kouzan|kerkis calligraphic/i,
 );
 
 my %initialFonts = (
@@ -323,17 +345,19 @@ my %initialFonts = (
 my %symbolFonts = (
   "value" => 200,          # Symbol
   "a" => qr/^(academicons)/i,
-  "c" => qr/^(caladings|ccicons|chess)/i,
-  "d" => qr/^(dingbats|drmsym)/i,
-  "e" => qr/^(elusiveicons|emoji)/i,
-  "f" => qr/^(fdsymbol|fourierorns)/i,
+  "c" => qr/^(caladings|ccicons|chess|cmsy|cmex)/i,
+  "d" => qr/^(dingbats|drmsym|d05)/i,
+  "e" => qr/^(elusiveicons|emoji|esint|euterpe)/i,
+  "f" => qr/^(fandol.?brail|fdsymbol|fourierorns|font(awesome|ello|.?mfizz))/i,
   "h" => qr/^(hots)/i,
-  "m" => qr/^(marvosym|material)/i,
+  "j" => qr/^jsmath.?(msam|cmsy|masm|msbm|wasy|cmex|stmary)/i,
+  "m" => qr/^(marvosym|material|msam|msbm)/i,
   "n" => qr/^(noto.*emoji)/i,
   "o" => qr/^(octicons)/i,
   "q" => qr/^(qtdingbits)/i,
+  "s" => qr/^stmary/i,
   "t" => qr/^(typicons|twemoji)/i,
-  "w" => qr/^(webdings)/i,
+  "w" => qr/^(webdings|wasy)/i,
 );
 
 if (open(FI,  "$cmd |")) {
@@ -402,7 +426,7 @@ if (open(FI,  "$cmd |")) {
       }
     }
     my @charlist = ();
-    if (defined($options{Contains}) || exists($options{PrintCharset})) {
+    if (defined($options{Contains}) || defined($options{NContains}) || exists($options{PrintCharset})) {
       if ($l =~ / charset=\"([^\"]+)\"/) {
         my @list = split(/\s+/, $1);
         for my $e (@list) {
@@ -416,6 +440,14 @@ if (open(FI,  "$cmd |")) {
           next NXTLINE if (! contains($g, \@charlist));
         }
       }
+      if (defined($options{NContains})) {
+        for my $g (@{$options{NContains}}) {
+          # Ignore if ANY char exist in @charlist
+          for (my $i = $g->[0]; $i <= $g->[1]; $i++) {
+            next NXTLINE if (contains([$i,$i], \@charlist));
+          }
+        }
+      }
     }
     my $props = "";
     my @errors = ();
@@ -440,16 +472,7 @@ if (open(FI,  "$cmd |")) {
       $props .= '(' . join(',', sort keys %usedlangs) . ')';
     }
     if (exists($options{PrintCharset})) {
-      my @out = ();
-      for my $rE (@charlist) {
-        if ($rE->[0] != $rE->[1]) {
-          push(@out, $rE->[0] . '-' . $rE->[1]);
-        }
-        else {
-          push(@out, $rE->[0]);
-        }
-      }
-      $props .= '(' . join(',', @out) . ')';
+      $props .= '(' . &sprintIntervalls(\@charlist) . ')';
     }
     if (exists($options{PrintScripts}) || defined($options{Scripts}) || defined($options{NScripts}) || exists($options{Math})) {
       my @scripts = ();
@@ -667,6 +690,9 @@ sub getftype($$)
       return($ftypes{100}); # Sans Serif
     }
   }
+  elsif ($style eq "PatchSans" && $fontname eq "font") {
+    return($ftypes{200});  # Symbol
+  }
   elsif ($fontname =~ /serif|times|mincho|batang/i) {
     if ($fontname =~ /good times/i) {
       return($ftypes{100}); # Sans Serif
@@ -676,7 +702,7 @@ sub getftype($$)
     }
   }
   # Now check for fonts without a hint in font name
-  if ($fontname =~ /([a-z])/i) {
+  if ($fontname =~ /^([a-z])/i) {
     my $key = lc($1);
     for my $rFonts (\%sansFonts, \%scriptFonts, \%fraktFonts, \%fancyFonts, \%initialFonts, \%symbolFonts) {
       if (defined($rFonts->{$key})) {
@@ -719,17 +745,12 @@ sub getweight($$)
 {
   my ($fontname, $style) = @_;
   my $result = undef;
-  for my $key (keys %weights) {
-    next if ($key !~ /^\d+$/);
-    my $val = $weights{$key};
-    for my $info ($style, $fontname) {
+  for my $info ($style, $fontname) {
+    for my $key (keys %weights) {
+      next if ($key !~ /^\d+$/);
+      my $val = $weights{$key};
       if ($info =~ /\b$val\b/i) {
-        if ($val eq "Regular") {
-          $result = $val;    # It may refer to width
-        }
-        else {
-          return($val);
-        }
+        return($val);
       }
     }
   }
@@ -777,7 +798,7 @@ sub getspacing($$)
       return($spacings{$key});
     }
   }
-  if ("$fontname $style" =~ /(mono|typewriter|cursor|fixed)\b/i) {
+  if ("$fontname $style" =~ /(\bmono\b|luximono|typewriter|cursor|fixed)\b/i) {
     return($spacings{100}); # Mono
   }
   else {
@@ -811,8 +832,19 @@ sub getproperties($$$$)
     my $val1 = $rget->($newfam, $newstyle);
     my $val;
     if (defined($val2) && defined($val1) && ($val2 ne $val1)) {
-      push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, selecting internal $txt($val2)");
-      $val = $val2;
+      if (($txt =~/^(weight|slant)$/) && ($newstyle =~ /$val1/)){
+        # style overrides weight and slant
+        push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from style");
+        $val = $val1;
+      }
+      elsif ($newfam =~ /$val1/) {
+        push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val1 from fontname");
+        $val = $val1;
+      }
+      else {
+        push(@{$rerrors}, "Fontname($fontname),Style($style): Values for $txt ($val1 != $val2) differ, pick $val2 from $txt-property");
+        $val = $val2;
+      }
     }
     elsif (! defined($val2)) {
       $val = $val1;
@@ -869,6 +901,7 @@ sub correctstyle($)
   $style =~ s/\b(SC|Small(caps(alt)?)?)\b/SmallCaps/i;
   $style =~ s/w3 mono/Dual/i;
   $style =~ s/Regul[ea]r/Regular/i;
+  $style =~ s/Megablack/ExtraBlack/i;
   $style =~ s/  +/ /g;
   return($style);
 }
@@ -921,9 +954,8 @@ sub decimalUnicode($)
 }
 
 
-# check if the glyph-value $d is contained
+# check if the glyph-values in interval @{$ri} are contained
 # in one of the (sorted) intervals
-# Inputs as intervals
 sub contains($$)
 {
   # ok if
@@ -941,3 +973,18 @@ sub contains($$)
   }
   return 0;
 }
+
+sub sprintIntervalls($)
+{
+  my ($rList) = @_;
+  my @out = ();
+  for my $rE (@{$rList}) {
+    if ($rE->[0] != $rE->[1]) {
+      push(@out, $rE->[0] . '-' . $rE->[1]);
+    }
+    else {
+      push(@out, $rE->[0]);
+    }
+  }
+  return join(',', @out);
+}