The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit 03943ef730aa5dc6bb61433d4cbe35f082614da0
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat Aug 18 09:58:19 2012 +0200

    Issue a warning if a LaTeX font is not available
    
    Also output font in source preview notwithstanding availability.

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 80f563d..87bbe66 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2859,14 +2859,22 @@ string const BufferParams::loadFonts(string const & rm,
 
        // Tex Fonts
        bool const ot1 = (font_encoding() == "default" || font_encoding() == 
"OT1");
+       bool const dryrun = features.runparams().dryrun;
 
        // ROMAN FONTS
        LaTeXFont roman = theLaTeXFonts().getLaTeXFont(from_ascii(rm));
-       if (roman.switchdefault())
-               os << "\\renewcommand{\\rmdefault}{" << to_ascii(roman.name()) 
<< "}\n";
-       else {
+       if (roman.switchdefault()) {
+               if (roman.available(ot1) || dryrun)
+                       os << "\\renewcommand{\\rmdefault}{" << 
to_ascii(roman.name()) << "}\n";
+               else
+                       frontend::Alert::warning(_("Font not available"),
+                                       bformat(_("The LaTeX package `%1$s' 
needed for the font `%2$s'\n"
+                                                 "is not available on your 
system. LyX will fall back to the default font."),
+                                               roman.requires(), 
roman.guiname()), true);
+       } else {
                bool const complete = (sf == "default" && tt == "default");
-               string const package = roman.getAvailablePackage(ot1, complete);
+               string const package =
+                       roman.getAvailablePackage(dryrun, ot1, complete);
                string const packageopts = roman.getPackageOptions(ot1, sc, 
osf);
                if (packageopts.empty() && !package.empty())
                        os << "\\usepackage{" << package << "}\n";
@@ -2878,10 +2886,16 @@ string const BufferParams::loadFonts(string const & rm,
 
        // SANS SERIF
        LaTeXFont sans = theLaTeXFonts().getLaTeXFont(from_ascii(sf));
-       if (sans.switchdefault())
-               os << "\\renewcommand{\\sfdefault}{" << to_ascii(sans.name()) 
<< "}\n";
-       else {
-               string const package = sans.getAvailablePackage(ot1);
+       if (sans.switchdefault()) {
+               if (sans.available(ot1) || dryrun)
+                       os << "\\renewcommand{\\sfdefault}{" << 
to_ascii(sans.name()) << "}\n";
+               else
+                       frontend::Alert::warning(_("Font not available"),
+                                       bformat(_("The LaTeX package `%1$s' 
needed for the font `%2$s'\n"
+                                                 "is not available on your 
system. LyX will fall back to the default font."),
+                                               sans.requires(), 
sans.guiname()), true);
+       } else {
+               string const package = sans.getAvailablePackage(dryrun, ot1);
                string const packageopts = sans.getPackageOptions(ot1, sc, osf, 
sfscale);
                if (packageopts.empty() && !package.empty())
                        os << "\\usepackage{" << package << "}\n";
@@ -2891,10 +2905,16 @@ string const BufferParams::loadFonts(string const & rm,
 
        // MONOSPACED/TYPEWRITER
        LaTeXFont mono = theLaTeXFonts().getLaTeXFont(from_ascii(tt));
-       if (mono.switchdefault())
-               os << "\\renewcommand{\\ttdefault}{" << to_ascii(mono.name()) 
<< "}\n";
-       else {
-               string const package = mono.getAvailablePackage(ot1);
+       if (mono.switchdefault()) {
+               if (mono.available(ot1) || dryrun)
+                       os << "\\renewcommand{\\ttdefault}{" << 
to_ascii(mono.name()) << "}\n";
+               else
+                       frontend::Alert::warning(_("Font not available"),
+                                       bformat(_("The LaTeX package `%1$s' 
needed for the font `%2$s'\n"
+                                                 "is not available on your 
system. LyX will fall back to the default font."),
+                                               mono.requires(), 
mono.guiname()), true);
+       } else {
+               string const package = mono.getAvailablePackage(dryrun, ot1);
                string const packageopts = mono.getPackageOptions(ot1, sc, osf, 
ttscale);
                if (packageopts.empty() && !package.empty())
                        os << "\\usepackage{" << package << "}\n";
diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
index 8d18a04..0fd1d5b 100644
--- a/src/LaTeXFonts.cpp
+++ b/src/LaTeXFonts.cpp
@@ -15,10 +15,13 @@
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 
+#include "frontends/alert.h"
+
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 
@@ -76,15 +79,22 @@ bool LaTeXFont::providesScale(bool ot1) const
 }
 
 
-string const LaTeXFont::getAvailablePackage(bool ot1, bool complete)
+string const LaTeXFont::getAvailablePackage(bool dryrun, bool ot1, bool 
complete)
 {
        if (ot1 && !ot1package_.empty()) {
-               if (ot1package_ != "none" && 
LaTeXFeatures::isAvailable(to_ascii(ot1package_)))
+               if (ot1package_ != "none"
+                   && (LaTeXFeatures::isAvailable(to_ascii(ot1package_)) || 
dryrun))
                        return to_ascii(ot1package_);
+               if (!dryrun && ot1package_ != "none")
+                       frontend::Alert::warning(_("Font not available"),
+                                       bformat(_("The LaTeX package `%1$s' 
needed for the font `%2$s'\n"
+                                                 "is not available on your 
system. LyX will fall back to the default font."),
+                                               ot1package_, guiname_), true);
                return string();
        }
+       docstring dryrunpackage;
        if (complete && !completepackage_.empty()) {
-               if (LaTeXFeatures::isAvailable(to_ascii(completepackage_)))
+               if (LaTeXFeatures::isAvailable(to_ascii(completepackage_)) || 
dryrun)
                        return to_ascii(completepackage_);
        }
        if (!package_.empty()) {
@@ -98,6 +108,14 @@ string const LaTeXFont::getAvailablePackage(bool ot1, bool 
complete)
                                        return to_ascii(altpackages_[i]);
                        }
                }
+               // Output unavailable packages in source preview
+               if (dryrun)
+                       return to_ascii(package_);
+               docstring const req = requires_.empty() ? package_ : requires_;
+                       frontend::Alert::warning(_("Font not available"),
+                                       bformat(_("The LaTeX package `%1$s' 
needed for the font `%2$s'\n"
+                                                 "is not available on your 
system. LyX will fall back to the default font."),
+                                               req, guiname_), true);
        }
        return string();
 }
diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h
index 19dfe10..3f8b135 100644
--- a/src/LaTeXFonts.h
+++ b/src/LaTeXFonts.h
@@ -64,7 +64,9 @@ public:
        /// Does this font provide scaling?
        bool providesScale(bool ot1 = false) const;
        /// Return the preferred available package 
-       std::string const getAvailablePackage(bool ot1 = false, bool complete = 
false);
+       std::string const getAvailablePackage(bool dryrun = false,
+                                             bool ot1 = false,
+                                             bool complete = false);
        /// Return the package options
        std::string const getPackageOptions(bool const & ot1,
                                            bool const & sc,

-----------------------------------------------------------------------

Summary of changes:
 src/BufferParams.cpp |   44 ++++++++++++++++++++++++++++++++------------
 src/LaTeXFonts.cpp   |   24 +++++++++++++++++++++---
 src/LaTeXFonts.h     |    4 +++-
 3 files changed, 56 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to