The branch, master, has been updated.

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

commit a9ad5c3337f5ed5855c3ebf7719d0cc31f1b7bbb
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat Aug 18 11:57:16 2012 +0200

    Factor out duplicated code

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 87bbe66..24613e5 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2785,17 +2785,7 @@ string const BufferParams::loadFonts(string const & rm,
                                     bool const & use_systemfonts,
                                     LaTeXFeatures & features) const
 {
-       /* The LaTeX font world is in a flux. In the PSNFSS font interface,
-          several packages have been replaced by others, that might not
-          be installed on every system. We have to take care for that
-          (see psnfss.pdf). We try to support all psnfss fonts as well
-          as the fonts that have become de facto standard in the LaTeX
-          world (e.g. Latin Modern). We do not support obsolete fonts
-          (like PSLatex). In general, it should be possible to mix any
-          rm font with any sf or tt font, respectively. (JSpitzm)
-          TODO:
-               -- separate math fonts.
-       */
+       // TODO: separate math fonts.
 
        if (rm == "default" && sf == "default" && tt == "default")
                //nothing to do
@@ -2860,67 +2850,16 @@ string const BufferParams::loadFonts(string const & rm,
        // Tex Fonts
        bool const ot1 = (font_encoding() == "default" || font_encoding() == 
"OT1");
        bool const dryrun = features.runparams().dryrun;
+       bool const complete = (sf == "default" && tt == "default");
 
        // ROMAN FONTS
-       LaTeXFont roman = theLaTeXFonts().getLaTeXFont(from_ascii(rm));
-       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(dryrun, ot1, complete);
-               string const packageopts = roman.getPackageOptions(ot1, sc, 
osf);
-               if (packageopts.empty() && !package.empty())
-                       os << "\\usepackage{" << package << "}\n";
-               else if (!packageopts.empty() && !package.empty())
-                       os << "\\usepackage[" << packageopts << "]{" << package 
<< "}\n";
-       }
-       if (osf && roman.providesOSF(ot1) && !roman.osfpackage().empty())
-               os << "\\usepackage{" << to_ascii(roman.osfpackage()) << "}\n";
+       os << theLaTeXFonts().getLaTeXFont(from_ascii(rm)).getLaTeXCode(dryrun, 
ot1, complete, sc, osf);
 
        // SANS SERIF
-       LaTeXFont sans = theLaTeXFonts().getLaTeXFont(from_ascii(sf));
-       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";
-               else if (!packageopts.empty() && !package.empty())
-                       os << "\\usepackage[" << packageopts << "]{" << package 
<< "}\n";
-       }
+       os << theLaTeXFonts().getLaTeXFont(from_ascii(sf)).getLaTeXCode(dryrun, 
ot1, complete, sc, osf, sfscale);
 
        // MONOSPACED/TYPEWRITER
-       LaTeXFont mono = theLaTeXFonts().getLaTeXFont(from_ascii(tt));
-       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";
-               else if (!packageopts.empty() && !package.empty())
-                       os << "\\usepackage[" << packageopts << "]{" << package 
<< "}\n";
-       }
+       os << theLaTeXFonts().getLaTeXFont(from_ascii(tt)).getLaTeXCode(dryrun, 
ot1, complete, sc, osf, ttscale);
 
        return os.str();
 }
diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
index 1e89e4c..562a8fc 100644
--- a/src/LaTeXFonts.cpp
+++ b/src/LaTeXFonts.cpp
@@ -92,7 +92,7 @@ string const LaTeXFont::getAvailablePackage(bool dryrun, bool 
ot1, bool complete
                                                ot1package_, guiname_), true);
                return string();
        }
-       if (complete && !completepackage_.empty()) {
+       if (family_ == "rm" && complete && !completepackage_.empty()) {
                if (LaTeXFeatures::isAvailable(to_ascii(completepackage_)) || 
dryrun)
                        return to_ascii(completepackage_);
        }
@@ -120,8 +120,7 @@ string const LaTeXFont::getAvailablePackage(bool dryrun, 
bool ot1, bool complete
 }
 
 
-string const LaTeXFont::getPackageOptions(bool const & ot1, bool const & sc,
-                                         bool const & osf, int const & scale)
+string const LaTeXFont::getPackageOptions(bool ot1, bool sc, bool osf, int 
scale)
 {
        if (ot1 && !ot1package_.empty())
                return string();
@@ -146,6 +145,40 @@ string const LaTeXFont::getPackageOptions(bool const & 
ot1, bool const & sc,
 }
 
 
+string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, 
bool sc,
+                                    bool osf, int const & scale)
+{
+       ostringstream os;
+
+       if (switchdefault_) {
+               if (family_.empty()) {
+                       LYXERR0("Error: Font `" << name_ << "' has no family 
defined!");
+                       return string();
+               }
+               if (available(ot1) || dryrun)
+                       os << "\\renewcommand{\\" << to_ascii(family_) << 
"default}{"
+                       << to_ascii(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."),
+                                               requires_, guiname_), true);
+       } else {
+               string const package =
+                       getAvailablePackage(dryrun, ot1, complete);
+               string const packageopts = getPackageOptions(ot1, sc, osf, 
scale);
+               if (packageopts.empty() && !package.empty())
+                       os << "\\usepackage{" << package << "}\n";
+               else if (!packageopts.empty() && !package.empty())
+                       os << "\\usepackage[" << packageopts << "]{" << package 
<< "}\n";
+       }
+       if (osf && providesOSF(ot1) && !osfpackage_.empty())
+               os << "\\usepackage{" << to_ascii(osfpackage_) << "}\n";
+
+       return os.str();
+}
+
+
 bool LaTeXFont::readFont(Lexer & lex)
 {
        enum LaTeXFontTags {
diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h
index 3f8b135..d12738e 100644
--- a/src/LaTeXFonts.h
+++ b/src/LaTeXFonts.h
@@ -63,20 +63,24 @@ public:
        bool providesSC(bool ot1 = false) const;
        /// Does this font provide scaling?
        bool providesScale(bool ot1 = false) const;
-       /// Return the preferred available package 
-       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,
-                                           bool const & osf,
-                                           int const & scale = 100);
+       /// Return the LaTeX Code
+       std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
+                                      bool sc, bool osf,
+                                      int const & scale = 100);
        ///
        bool read(Lexer & lex);
        ///
        bool readFont(Lexer & lex);
 private:
+       /// Return the preferred available package 
+       std::string const getAvailablePackage(bool dryrun,
+                                             bool ot1,
+                                             bool complete);
+       /// Return the package options
+       std::string const getPackageOptions(bool ot1,
+                                           bool sc,
+                                           bool osf,
+                                           int scale);
        ///
        docstring name_;
        ///

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

Summary of changes:
 src/BufferParams.cpp |   71 +++----------------------------------------------
 src/LaTeXFonts.cpp   |   39 +++++++++++++++++++++++++--
 src/LaTeXFonts.h     |   22 +++++++++------
 3 files changed, 54 insertions(+), 78 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to