]> git.lyx.org Git - lyx.git/blobdiff - development/autotests/useSystemFonts.pl
Customization: correct some color names.
[lyx.git] / development / autotests / useSystemFonts.pl
index 7b71c82713b3bda61900e49fc494da725b92452d..f0183fa776fd5ac6d6daa62802b80bdcf58e4556 100644 (file)
@@ -59,10 +59,14 @@ sub copyJobPending($$);
 sub addNewJob($$$$$);
 sub addFileCopyJob($$$$);
 sub getNewNameOf($$);
+sub getlangs($$);
+sub simplifylangs($);
+sub getLangEntry();
 
 # convert lyx file to be compilable with xetex
 
-my ($source, $dest, $format, $fontT, $rest) = @ARGV;
+my ($source, $dest, $format, $fontT, $languageFile, $rest) = @ARGV;
+my %encodings = ();      # Encoding with TeX fonts, depending on language tag
 
 diestack("Too many arguments") if (defined($rest));
 diestack("Sourcefilename not defined") if (! defined($source));
@@ -75,11 +79,18 @@ $dest = File::Spec->rel2abs($dest);
 
 my %font = ();
 my $lang = "main";
-if ($source =~ /\/([a-z][a-z](_[A-Z][A-Z])?)\//) {
+if ($source =~ /\/([a-z][a-z](_[A-Z][A-Z])?)[\/_]/) {
   $lang = $1;
 }
+
+my $inputEncoding = undef;
 if ($fontT eq "systemF") {
-  if ($lang =~ /^(he|el|ru|uk|main)$/) {
+  if ($lang =~ /^(ru|uk|sk|el)$/) {
+    $font{roman} = "DejaVu Serif";
+    $font{sans} = "DejaVu Sans";
+    $font{typewriter} = "DejaVu Sans Mono";
+  }
+  elsif ($lang =~ /^(he)$/) {
     $font{roman} = "FreeSans";
     $font{sans} = "FreeSans";
     $font{typewriter} = "FreeSans";
@@ -94,15 +105,48 @@ if ($fontT eq "systemF") {
     $font{sans} = "WenQuanYi Micro Hei";
     $font{typewriter} = "WenQuanYi Micro Hei";
   }
+  elsif ($lang eq "ko" ) {
+    $font{roman} = "NanumGothic"; # NanumMyeongjo, NanumGothic Eco, NanumGothicCoding
+    $font{sans} = "NanumGothic";
+    $font{typewriter} = "NanumGothic";
+  }
+  elsif ($lang eq "ar" ) {
+    # available in 'fonts-sil-scheherazade' package
+    $font{roman} = "Scheherazade";
+    $font{sans} = "Scheherazade";
+    $font{typewriter} = "Scheherazade";
+  }
   else {
     # default system fonts
-    $font{roman} = "FreeSans";
+    $font{roman} = "FreeSerif";
     $font{sans} = "FreeSans";
-    $font{typewriter} = "FreeSans";
+    $font{typewriter} = "FreeMono";
   }
 }
-else {
+elsif (0) { # set to '1' to enable setting of inputencoding
   # use tex font here
+  my %encoding = ();
+  if (defined($languageFile)) {
+    # The 2 lines below does not seem to have any effect
+    #&getlangs($languageFile, \%encoding);
+    #&simplifylangs(\%encoding);
+  }
+  if ($format =~ /^(pdf4)$/) { # xelatex
+    # set input encoding to 'ascii' always
+    $inputEncoding = {
+      "search" => '.*', # this will be substituted from '\inputencoding'-line
+      "out" => "ascii",
+    };
+  }
+  elsif ($format =~ /^(dvi3|pdf5)$/) { # (dvi)?lualatex
+    # when to set input encoding to 'ascii'?
+    if (defined($encoding{$lang})) {
+      $inputEncoding = {
+       "search" => '.*', # this will be substituted from '\inputencoding'-line
+       "out" => $encoding{$lang},
+      };
+    }
+  }
 }
 
 my $sourcedir = dirname($source);
@@ -159,10 +203,11 @@ sub interpretedCopy($$$$)
   diestack("could not read \"$source\"") if (!open(FI, $source));
   diestack("could not write \"$dest\"") if (! open(FO, '>', $dest));
 
-  initLyxStack(\%font, $fontT);
+  initLyxStack(\%font, $fontT, $inputEncoding);
 
   while (my $l = <FI>) {
-    chomp($l);
+    $l =~ s/[\n\r]+$//;
+    #chomp($l);
     my $rStatus = checkLyxLine($l);
     if ($rStatus->{found}) {
       my $rF = $rStatus->{result};
@@ -364,3 +409,85 @@ sub getNewNameOf($$)
   }
   return($resultf);
 }
+
+sub getlangs($$)
+{
+  my ($languagefile, $rencoding) = @_;
+
+  if (open(FI, $languagefile)) {
+    while (my $l = <FI>) {
+      if ($l =~ /^Language/) {
+        my ($lng, $enc) = &getLangEntry();
+        if (defined($lng)) {
+          $rencoding->{$lng} = $enc;
+        }
+      }
+    }
+    close(FI);
+  }
+}
+
+sub simplifylangs($)
+{
+  my ($rencoding) = @_;
+  my $base = "";
+  my $enc = "";
+  my $differ = 0;
+  my @klist = ();
+  my @klist2 = ();
+  for my $k (reverse sort keys %{$rencoding}) {
+    my @tag = split('_', $k);
+    if ($tag[0] eq $base) {
+      push(@klist, $k);
+      if ($rencoding->{$k} ne $enc) {
+       $differ = 1;
+      }
+    }
+    else {
+      # new base, check that old base was OK
+      if ($base ne "") {
+       if ($differ == 0) {
+         $rencoding->{$base} = $enc;
+         push(@klist2, @klist);
+       }
+      }
+      @klist = ($k);
+      $base = $tag[0];
+      $enc = $rencoding->{$k};
+      $differ = 0;
+    }
+  }
+  if ($base ne "") {
+    # close handling for last entry too
+    if ($differ == 0) {
+      $rencoding->{$base} = $enc;
+      push(@klist2, @klist);
+    }
+  }
+  for my $k (@klist2) {
+    delete($rencoding->{$k});
+  }
+}
+
+sub getLangEntry()
+{
+  my ($lng, $enc) = (undef, undef);
+  while (my $l = <FI>) {
+    chomp($l);
+    if ($l =~ /^\s*Encoding\s+([^ ]+)\s*$/) {
+      $enc = $1;
+    }
+    elsif ($l =~ /^\s*LangCode\s+([^ ]+)\s*$/) {
+      $lng = $1;
+    }
+    elsif ($l =~ /^\s*End\s*$/) {
+      last;
+    }
+  }
+  if (defined($lng) && defined($enc)) {
+    return($lng, $enc);
+  }
+  else {
+    return(undef, undef);
+  }
+}