]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
This commit adds some new functionality to the modules stuff. In particular, it intro...
[lyx.git] / src / BufferParams.cpp
index 44573db167afc572f96e556b24328c21411063e3..9e2ff3c57e20702ea2b02280480f8880b1158e42 100644 (file)
 #include <algorithm>
 #include <sstream>
 
-using std::count;
-using std::endl;
-using std::find;
-using std::string;
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-using std::pair;
-using std::string;
-using lyx::support::FileName;
-using lyx::support::libFileSearch;
-using lyx::support::bformat;
-using lyx::support::rtrim;
-using lyx::support::tokenPos;
-using lyx::support::prefixIs;
+using namespace std;
+using namespace lyx::support;
 
 
 static char const * const string_paragraph_separation[] = {
@@ -150,7 +137,7 @@ QuotesLangTranslator const & quoteslangtranslator()
 
 
 // Paper size
-typedef Translator<std::string, PAPER_SIZE> PaperSizeTranslator;
+typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
 
 
 PaperSizeTranslator const init_papersizetranslator()
@@ -327,6 +314,7 @@ BufferParams::BufferParams()
        : pimpl_(new Impl)
 {
        setBaseClass(defaultTextclass());
+       makeTextClass();
        paragraph_separation = PARSEP_INDENT;
        quotes_language = InsetQuotes::EnglishQ;
        fontsize = "default";
@@ -474,8 +462,11 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
                string const classname = lex.getString();
                // if there exists a local layout file, ignore the system one
                // NOTE: in this case, the textclass (.cls file) is assumed to be available.
-               pair<bool, lyx::textclass_type> pp = textclasslist.addTextClass(
-                       classname, filepath.absFilename());
+               pair<bool, lyx::textclass_type> pp =
+                       make_pair(false, textclass_type(0));
+               if (!filepath.empty())
+                       pp = textclasslist.addTextClass(
+                               classname, filepath.absFilename());
                if (pp.first)
                        setBaseClass(pp.second);
                else {
@@ -507,7 +498,6 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
                readPreamble(lex);
        } else if (token == "\\begin_modules") {
                readModules(lex);
-               makeTextClass();
        } else if (token == "\\options") {
                lex.eatLine();
                options = lex.getString();
@@ -818,6 +808,85 @@ void BufferParams::writeFile(ostream & os) const
 }
 
 
+void BufferParams::validate(LaTeXFeatures & features) const
+{
+       if (!getTextClass().requires().empty()) {
+               vector<string> req = getTextClass().requires();
+               for (vector<string>::const_iterator it = req.begin();
+                    it != req.end(); ++it) {
+                       features.require(*it);
+               }
+       }
+
+       if (outputChanges) {
+               bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
+               bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
+                                 LaTeXFeatures::isAvailable("xcolor");
+
+               switch (features.runparams().flavor) {
+               case OutputParams::LATEX:
+                       if (dvipost) {
+                               features.require("ct-dvipost");
+                               features.require("dvipost");
+                       } else if (xcolorsoul) {
+                               features.require("ct-xcolor-soul");
+                               features.require("soul");
+                               features.require("xcolor");
+                       } else {
+                               features.require("ct-none");
+                       }
+                       break;
+               case OutputParams::PDFLATEX:
+                       if (xcolorsoul) {
+                               features.require("ct-xcolor-soul");
+                               features.require("soul");
+                               features.require("xcolor");
+                               // improves color handling in PDF output
+                               features.require("pdfcolmk"); 
+                       } else {
+                               features.require("ct-none");
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       // Floats with 'Here definitely' as default setting.
+       if (float_placement.find('H') != string::npos)
+               features.require("float");
+
+       // AMS Style is at document level
+       if (use_amsmath == package_on
+           || getTextClass().provides("amsmath"))
+               features.require("amsmath");
+       if (use_esint == package_on)
+               features.require("esint");
+
+       // the bullet shapes are buffer level not paragraph level
+       // so they are tested here
+       for (int i = 0; i < 4; ++i) {
+               if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i]) 
+                       continue;
+               int const font = user_defined_bullet(i).getFont();
+               if (font == 0) {
+                       int const c = user_defined_bullet(i).getCharacter();
+                       if (c == 16
+                           || c == 17
+                           || c == 25
+                           || c == 26
+                           || c == 31) {
+                               features.require("latexsym");
+                       }
+               } else if (font == 1) {
+                       features.require("amssymb");
+               } else if (font >= 2 && font <= 5) {
+                       features.require("pifont");
+               }
+       }
+}
+
+
 bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                              TexRow & texrow) const
 {
@@ -1302,24 +1371,16 @@ void BufferParams::setTextClass(TextClassPtr tc) {
 
 bool BufferParams::setBaseClass(textclass_type tc)
 {
-       bool retVal = true;
-       if (textclasslist[tc].load())
+       if (textclasslist[tc].load()) {
                baseClass_ = tc;
-       else {
-               docstring s = 
-                       bformat(_("The document class %1$s could not be loaded."),
-                from_utf8(textclasslist[tc].name()));
-               frontend::Alert::error(_("Could not load class"), s);
-               retVal = false;
+               return true;
        }
-       makeTextClass();
-       return retVal;
-}
-
-
-void BufferParams::setJustBaseClass(textclass_type tc)
-{ 
-       baseClass_ = tc; 
+       
+       docstring s = 
+               bformat(_("The document class %1$s could not be loaded."),
+               from_utf8(textclasslist[tc].name()));
+       frontend::Alert::error(_("Could not load class"), s);
+       return false;
 }
 
 
@@ -1332,6 +1393,7 @@ textclass_type BufferParams::getBaseClass() const
 void BufferParams::makeTextClass()
 {
        textClass_.reset(new TextClass(textclasslist[getBaseClass()]));
+       
        //FIXME It might be worth loading the children's modules here,
        //just as we load their bibliographies and such, instead of just 
        //doing a check in InsetInclude.
@@ -1344,7 +1406,7 @@ void BufferParams::makeTextClass()
                                bformat(_("The module %1$s has been requested by\n"
                                        "this document but has not been found in the list of\n"
                                        "available modules. If you recently installed it, you\n"
-                                       "probalby need to reconfigure LyX.\n"), from_utf8(modName));
+                                       "probably need to reconfigure LyX.\n"), from_utf8(modName));
                        frontend::Alert::warning(_("Module not available"),
                                        msg + _("Some layouts may not be available."));
                        lyxerr << "BufferParams::makeTextClass(): Module " <<
@@ -1352,19 +1414,26 @@ void BufferParams::makeTextClass()
                                        endl;
                        continue;
                }
-               FileName layout_file = libFileSearch("layouts", lm->filename);
+               if (!lm->isAvailable()) {
+                       docstring const msg =
+                                               bformat(_("The module %1$s requires a package that is\n"
+                                               "not available in your LaTeX installation. LaTeX output\n"
+                                               "may not be possible.\n"), from_utf8(modName));
+                       frontend::Alert::warning(_("Package not available"), msg);
+               }
+               FileName layout_file = libFileSearch("layouts", lm->getFilename());
                textClass_->read(layout_file, TextClass::MODULE);
        }
 }
 
 
-std::vector<string> const & BufferParams::getModules() const {
+vector<string> const & BufferParams::getModules() const {
        return layoutModules_;
 }
 
 
 
-bool BufferParams::addLayoutModule(string modName, bool makeClass) {
+bool BufferParams::addLayoutModule(string const & modName) {
        LayoutModuleList::const_iterator it = layoutModules_.begin();
        LayoutModuleList::const_iterator end = layoutModules_.end();
        for (; it != end; it++) {
@@ -1374,27 +1443,12 @@ bool BufferParams::addLayoutModule(string modName, bool makeClass) {
        if (it != layoutModules_.end())
                return false;
        layoutModules_.push_back(modName);
-       if (makeClass)
-               makeTextClass();
        return true;
 }
 
 
-bool BufferParams::addLayoutModules(std::vector<string>modNames)
-{
-       bool retval = true;
-       std::vector<string>::const_iterator it = modNames.begin();
-       std::vector<string>::const_iterator end = modNames.end();
-       for (; it != end; ++it)
-               retval &= addLayoutModule(*it, false);
-       makeTextClass();
-       return retval;
-}
-
-
 void BufferParams::clearLayoutModules() {
        layoutModules_.clear();
-       makeTextClass();
 }
 
 
@@ -1600,7 +1654,7 @@ void BufferParams::writeEncodingPreamble(odocstream & os,
 
                // Create a list with all the input encodings used
                // in the document
-               std::set<string> encodings =
+               set<string> encodings =
                        features.getEncodingSet(doc_encoding);
 
                // When the encodings EUC-JP-plain, JIS-plain, or SJIS-plainare used, the
@@ -1612,8 +1666,8 @@ void BufferParams::writeEncodingPreamble(odocstream & os,
 
                if (!encodings.empty() || package == Encoding::inputenc) {
                        os << "\\usepackage[";
-                       std::set<string>::const_iterator it = encodings.begin();
-                       std::set<string>::const_iterator const end = encodings.end();
+                       set<string>::const_iterator it = encodings.begin();
+                       set<string>::const_iterator const end = encodings.end();
                        if (it != end) {
                                os << from_ascii(*it);
                                ++it;